《Web课程设计》课程设计报告书前言Micro blog信息系统主要是一个校园微博系统,在该系统中可以注册、登录,同时还分普通会员登录及管理员登录。
通过登录后,可实现发布、查询、删除微博等各项功能。
关键字:信息系统微博登录系统分析1.设计目的:1.综合应用java程序设计、WEB程序设计、数据库应用、计算机网络等知识设计和实现我校Micro Blog信息系统。
2.通过上述设计和实现,加深对java程序设计、WEB程序设计、数据库应用、计算机网络相关理论的理解,锻炼综合应用所学知识分析问题和解决问题的能力。
3.培养软件开发的团队协作精神。
系统设计1.设计内容:(1)用户注册(2)用户登录(分一般用户和管理员)(3)某用户发布微博信息(4)浏览所有用户的微博信息(5)浏览指定用户的微博信息(6)查询某些用户或(且)某时间段或(且)某论题的微博信息。
(7)删除某些用户或(且)某时间段或(且)某论题的微博信息。
(8)统计分析某时间段的用户数量,微博数量。
(9)发布重大消息或提示信息(7-9基于管理员)2.设计环境:(1)完整实现设计内容所指定的功能(2)应用服务器采用Tomcat 6.0或以上(3)基于JSP编程(4)开发工具采用Eclipse + DreamWeaver(5)数据库采用ACCESS 2003(6)用户界面友好3.系统流程图:数据库设计在Micro blog信息系统中,共设计3张表。
本系统使用Access来创建数据表。
数据库的名称为WEB.mdb,三张表分别为admin、message、user。
表:admin表:message表:user系统实现代码Login.javapackage mybean.data;public class Login{ String logname,password,backNews="";boolean success=false;public void setLogname(String name) { logname=name;}public String getLogname(){return logname;}public void setPassword(String pw){ password=pw;}public String getPassword(){return password;}public String getBackNews(){ return backNews;}public void setBackNews(String s){ backNews=s;}public void setSuccess(boolean b){ success=b;}public boolean getSuccess(){ return success;}}Message.javapackage mybean.data;publicclass Message {String logname="",message="",time="",title="",backNews;publicvoid setLogname(String name){ logname=name;}public String getLogname(){ return logname;}publicvoid setTitle(String t){ title=t;}public String getTitle(){ return title;}publicvoid setTime(String t){ time=t;}public String getTime(){ return time;}public String getMessage(){ return message;}publicvoid setMessage(String m){ message=m;}public String getBackNews(){ return backNews;}publicvoid setBackNews(String s){ backNews=s;}}Register.javapackage mybean.data;publicclass Register{ String logname="",password="",qq="",email="", phone="";String backNews;publicvoid setLogname(String name){ logname=name;}public String getLogname(){ return logname;}publicvoid setQq(String q){ qq=q;}public String getQq(){ return qq;}publicvoid setPassword(String pw){ password=pw;}public String getPassword(){ return password;}publicvoid setEmail(String em){ email=em;}public String getEmail(){ return email;}publicvoid setPhone(String ph){ phone=ph;}public String getPhone(){ return phone;}public String getBackNews(){ return backNews;}publicvoid setBackNews(String s){ backNews=s;}}ConditionQuery.javapackage mybean.data;import java.sql.*;public class ConditionQuery{ String logname ;StringBuffer queryResultBylogname;public ConditionQuery(){ queryResultBylogname=new StringBuffer();try{ Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); }catch(Exception e){ }}public void setlogname(String s){ logname=s.trim();queryResultBylogname=new StringBuffer();}public String getlogname(){ return logname;}public StringBuffer getQueryResultBylogname(){ String condition="SELECT * FROM message Where logname = '"+logname+"'"; queryResultBylogname=f(condition);return queryResultBylogname;}private StringBuffer f(String condition){ StringBuffer str=new StringBuffer();Connection con;Statement sql;ResultSet rs;try { Stringuri="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=factory";con=DriverManager.getConnection("jdbc:odbc:4073","","");sql=con.createStatement();rs=sql.executeQuery(condition);str.append("<table border=1>");str.append("<th width=100>"+"logname");str.append("<th width=100>"+"title");str.append("<th width=100>"+"message");str.append("<th width=100>"+"time");while(rs.next()){ str.append("<tr>");str.append("<td>"+rs.getString(1)+"</td>");str.append("<td>"+rs.getString(2)+"</td>");str.append("<td>"+rs.getString(3)+"</td>");str.append("<td>"+rs.getString(4)+"</td>");str.append("</tr>");}str.append("<table border=1>");con.close();}catch(SQLException e){ System.out.println(e);}return str;}}HandleAdmin.javapackage myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleAdmin extends HttpServlet{ public void init(ServletConfig config) throws ServletException{ super.init(config);try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(Exception e){}}public String handleString(String s){ try{ byte bb[]=s.getBytes("iso-8859-1");s=new String(bb);}catch(Exception ee){}return s;}public void doPost(HttpServletRequest request,HttpServletResponseresponse)throws ServletException,IOException{ Connection con;PreparedStatement sql;Login loginBean=null;String backNews="";HttpSession session=request.getSession(true);try{ loginBean=(Login)session.getAttribute("login");if(loginBean==null){ loginBean=new Login();session.setAttribute("login",loginBean);}}catch(Exception ee){ loginBean=new Login();session.setAttribute("login",loginBean);}String logname=request.getParameter("logname").trim(),password=request.getParameter("password").trim();boolean ok=loginBean.getSuccess();logname=handleString(logname);password=handleString(password);if(ok==true&&logname.equals(loginBean.getLogname())){ backNews=logname+"你已经登录了";loginBean.setBackNews(backNews);}else{boolean boo=(logname.length()>0)&&(password.length()>0);try{ con=DriverManager.getConnection("jdbc:odbc:4073","",""); String condition="select * from admin where logname =? and password =?";sql=con.prepareStatement(condition);if(boo){ sql.setString(1,logname);sql.setString(2,password);ResultSet rs=sql.executeQuery();boolean m=rs.next();if(m==true){ backNews="管理员登录成功";loginBean.setBackNews(backNews);loginBean.setSuccess(true);loginBean.setLogname(logname);}else{ backNews="您登陆的管理员不存在,或密码不对";loginBean.setBackNews(backNews);loginBean.setSuccess(false);loginBean.setLogname(logname);loginBean.setPassword(password);}}else{ backNews="您输入的管理员不存在,或密码不对";loginBean.setBackNews(backNews);loginBean.setSuccess(false);loginBean.setLogname(logname);loginBean.setPassword(password);}con.close();}catch(SQLException exp){ backNews=""+exp;loginBean.setBackNews(backNews);loginBean.setSuccess(false);}}RequestDispatcherdispatcher=request.getRequestDispatcher("showAdminMess.jsp");dispatcher.forward(request, response);}public void doGet(HttpServletRequest request,HttpServletResponseresponse)throws ServletException,IOException{ doPost(request,response);}}HandleLogin.javapackage myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleLogin extends HttpServlet{ public void init(ServletConfig config) throws ServletException{ super.init(config);try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(Exception e){}}public String handleString(String s){ try{ byte bb[]=s.getBytes("iso-8859-1");s=new String(bb);}catch(Exception ee){}return s;}public void doPost(HttpServletRequest request,HttpServletResponseresponse)throws ServletException,IOException{ Connection con;PreparedStatement sql;Login loginBean=null;String backNews="";HttpSession session=request.getSession(true);try{ loginBean=(Login)session.getAttribute("login");if(loginBean==null){ loginBean=new Login();session.setAttribute("login",loginBean);}}catch(Exception ee){ loginBean=new Login();session.setAttribute("login",loginBean);}String logname=request.getParameter("logname").trim(),password=request.getParameter("password").trim();boolean ok=loginBean.getSuccess();logname=handleString(logname);password=handleString(password);if(ok==true&&logname.equals(loginBean.getLogname())){ backNews=logname+"你已经登录了";loginBean.setBackNews(backNews);}else{boolean boo=(logname.length()>0)&&(password.length()>0);try{ con=DriverManager.getConnection("jdbc:odbc:4073","",""); String condition="select * from user where logname =? and password =?";sql=con.prepareStatement(condition);if(boo){ sql.setString(1,logname);sql.setString(2,password);ResultSet rs=sql.executeQuery();boolean m=rs.next();if(m==true){ backNews="会员登录成功";loginBean.setBackNews(backNews);loginBean.setSuccess(true);loginBean.setLogname(logname);}else{ backNews="您输入的会员不存在,或密码不对";loginBean.setBackNews(backNews);loginBean.setSuccess(false);loginBean.setLogname(logname);loginBean.setPassword(password);}}else{ backNews="您输入的会员不存在,或密码不对";loginBean.setBackNews(backNews);loginBean.setSuccess(false);loginBean.setLogname(logname);loginBean.setPassword(password);}con.close();}catch(SQLException exp){ backNews=""+exp;loginBean.setBackNews(backNews);loginBean.setSuccess(false);}}RequestDispatcherdispatcher=request.getRequestDispatcher("showLoginMess.jsp");dispatcher.forward(request, response);}public void doGet(HttpServletRequest request,HttpServletResponseresponse)throws ServletException,IOException{ doPost(request,response);}}HandleMessage.javapackage myservlet.control;import mybean.data.*;import java.util.Date;import java.text.SimpleDateFormat;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleMessage extends HttpServlet{ public void init(ServletConfig config) throws ServletException{ super.init(config);try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(Exception e){}}public String handleString(String s){ try{ byte bb[]=s.getBytes("iso-8859-1");s=new String(bb);}catch(Exception ee){}return s;}public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ HttpSession session=request.getSession(true);Login login=(Login)session.getAttribute("login"); //获取用户登录时的Javabeanboolean ok=true;if(login==null){ ok=false;response.sendRedirect("login.jsp"); //重定向到登录页面}if(ok==true){ continueWork(request,response);}}public void continueWork(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ HttpSession session=request.getSession(true);Login login=(Login)session.getAttribute("login");Connection con;PreparedStatement sql;String logname=login.getLogname();Message mess=new Message();request.setAttribute("message",mess);String message=request.getParameter("message");String title=request.getParameter("title");Date now = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//参数为你需要的时间格式String time = sdf.format(now);String backNews="";try{ con=DriverManager.getConnection("jdbc:odbc:4073","","");String insertCondition="INSERT INTO message VALUES (?,?,?,?)";sql=con.prepareStatement(insertCondition);sql.setString(1,handleString(logname));sql.setString(2,handleString(title));sql.setString(3,handleString(message));sql.setString(4,handleString(time));int m=sql.executeUpdate();if(m!=0){ backNews="发布微博成功";mess.setBackNews(backNews);mess.setLogname(logname);mess.setTitle(handleString(title));mess.setMessage(handleString(message));mess.setTime(time);}con.close();}catch(SQLException exp){ backNews="信息有非法字符"+exp;mess.setBackNews(backNews);}RequestDispatcher dispatcher=request.getRequestDispatcher("showMessage.jsp");//转发dispatcher.forward(request, response);}public void doGet(HttpServletRequest request,HttpServletResponseresponse)throws ServletException,IOException{ doPost(request,response);}}HandleRegister.javapackage myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class HandleRegister extends HttpServlet{ public void init(ServletConfig config) throws ServletException{ super.init(config);try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}catch(Exception e){}}public String handleString(String s){ try{ byte bb[]=s.getBytes("iso-8859-1");s=new String(bb);}catch(Exception ee){}return s;}public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ Connection con;PreparedStatement sql;Register reg=new Register();request.setAttribute("register",reg);String logname=request.getParameter("logname").trim(),password=request.getParameter("password").trim(),qq=request.getParameter("qq").trim(),email=request.getParameter("email").trim(),phone=request.getParameter("phone").trim();if(logname==null)logname="";if(password==null)password="";boolean isLD=true;for(int i=0;i<logname.length();i++){ char c=logname.charAt(i);if(!((c<='z'&&c>='a')||(c<='Z'&&c>='A')||(c<='9'&&c>='0'))) isLD=false;}boolean boo=logname.length()>0&&password.length()>0&&isLD;String backNews="";try{ con=DriverManager.getConnection("jdbc:odbc:4073","","");String insertCondition="INSERT INTO user VALUES (?,?,?,?,?)"; sql=con.prepareStatement(insertCondition);if(boo){ sql.setString(1,handleString(logname));sql.setString(2,handleString(password));sql.setString(3,handleString(qq));sql.setString(4,phone);sql.setString(5,email);int m=sql.executeUpdate();if(m!=0){ backNews="会员注册成功";reg.setBackNews(backNews);reg.setLogname(logname);reg.setPassword(handleString(password));reg.setQq(handleString(qq));reg.setEmail(handleString(email));reg.setPhone(phone);}}else{ backNews="会员名中有非法字符";reg.setBackNews(backNews);}con.close();}catch(SQLException exp){ backNews="该会员名已被注册,请换会员名"+exp;reg.setBackNews(backNews);}RequestDispatcher dispatcher=request.getRequestDispatcher("showRegisterMess.jsp");//转发dispatcher.forward(request, response);}public void doGet(HttpServletRequest request,HttpServletResponseresponse)throws ServletException,IOException{ doPost(request,response);}}web.xml<?xmlversion="1.0"encoding="ISO-8859-1"?><web-app><servlet><servlet-name>register</servlet-name><servlet-class>myservlet.control.HandleRegister</servlet-class></servlet><servlet-mapping><servlet-name>register</servlet-name><url-pattern>/helpRegister</url-pattern></servlet-mapping><servlet><servlet-name>login</servlet-name><servlet-class>myservlet.control.HandleLogin</servlet-class></servlet><servlet-mapping><servlet-name>login</servlet-name><url-pattern>/helpLogin</url-pattern></servlet-mapping><servlet><servlet-name>admin</servlet-name><servlet-class>myservlet.control.HandleAdmin</servlet-class></servlet><servlet-mapping><servlet-name>admin</servlet-name><url-pattern>/helpAdmin</url-pattern></servlet-mapping><servlet><servlet-name>message</servlet-name><servlet-class>myservlet.control.HandleMessage</servlet-class></servlet><servlet-mapping><servlet-name>message</servlet-name><url-pattern>/helpMessage</url-pattern></servlet-mapping></web-app>head.txt<%@ page language="java" contentType="text/html; charset=GB2312"pageEncoding="GB2312"%><CENTER><Font size=7 color=red><P>广东海洋大学寸金学院微博系统</Font></CENTER> <table cellSpacing="1" cellPadding="1" width="560" align="center"border="0" ><tr valign="bottom"><td><A href="register.jsp"><font size=3>会员注册</font></A></td><td><A href="login.jsp"><font size=3>会员登录</font></A></td><td><A href="admin.jsp"><font size=3>管理员登录</font></A></td></tr></Font></table><hr />head1.txt<%@ page language="java" contentType="text/html; charset=GB2312"pageEncoding="GB2312"%><CENTER><Font size=5><P>广东海洋大学寸金学院微博系统</Font></CENTER><table cellSpacing="1" cellPadding="1" width="560" align="center"border="0" ><tr valign="bottom"><td><A href="message.jsp"><font size=3>发布新微博</font></A></td><td><A href="showByjdbcOdbc.jsp"><font size=3>浏览已发微博</font></A></td> <td><A href="ychaxunFile.jsp"><font size=3>查询功能</font></A></td><td><A href="index.jsp"><font size=3>主页</font></A></td></Font></table><hr />head3.txt<%@ page language="java" contentType="text/html; charset=GB2312"pageEncoding="GB2312"%><CENTER><Font size=5><P>广东海洋大学寸金学院微博系统</Font></CENTER><table cellSpacing="1" cellPadding="1" width="560" align="center"border="0" ><tr valign="bottom"><td><A href="gchaxunFile.jsp"><font size=3>查询功能</font></A></td><td><A href="deleteFile.jsp"><font size=3>删除功能</font></A></td><td><A href="wholeshowFile.jsp"><font size=3>统计功能</font></A></td><td><A href="index.jsp"><font size=3>主页</font></A></td></Font></table><hr />index.jsp<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><BODY bgcolor=lightblue ><%@ page language="java" contentType="text/html; charset=GB2312"pageEncoding="GB2312"%><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><title></title><style type="text/css"><!--.a {font-size: 24px;color: #00F;text-align: center;}--></style></head><body><HEAD><%@ include file="head.txt" %></HEAD><CENTER> <h1><Font color=red Size=4 class="a">欢迎您使用本系统</font></h1> </img><img src="aa.jpg" width="670" height="448"></CENTER></body></html>admin.jsp<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><%@ page language="java" contentType="text/html; charset=GB2312"pageEncoding="GB2312"%><meta http-equiv="Content-Type" content="text/html; charset=GB2312"><title></title></head><BODY bgcolor=lightblue ><HEAD><%@ include file="head.txt" %></HEAD><Font size=2><CENTER><BR><BR><table border=2><tr> <th>管理员登录</th></tr><FORM action="helpAdmin" Method="post"><tr><td>名称:<Input type=text name="logname"></td></tr><tr><td>密码:<Input type=password name="password"></td></tr></table><BR><Input type=submit name="g" value="确定"></Form></CENTER></BODY></html>deleteFile.jsp<%@ page contentType="text/html;charset=utf-8" %><%@ page import="java.sql.*" %><HTML><style type="text/css"><!--.a {font-size: 24px;text-align: left;}.a {text-align: center;}.a {text-align: center;}.a {text-align: center;}.a {font-size: 16px;}.q {font-size: 24px;}--></style><BODY><p><Font size=2><BODY bgcolor=lightblue ></Font></p><p><font size="2" class="a"><span class="q">微博删除系统</span></font></p><Font size=2><FORM action="" Method="post" class="a">管理员删除会员的微博 <BR>输入会员名:<Input type=text name="number"><Input type=submit name="g" value="确定"></Form><FORM action="" Method="post" class="a">删除会员主题的微博<BR>输入主题名:<Input type=text name="lunti"><Input type=submit name="b" value="确定"></Form><FORM action="" Method="post" class="a">删除某时间内的微博<BR> 时间在<Input type=text name="Min" size=10>至<Input type=text name="Max" size=10>之间<Input type=submit value="确定"></Form></Font><p><Font size=2><%StringBuffer str=new StringBuffer(); //用来存储查询结果Connection con;Statement sql;ResultSet rs;String lu="",condition="",num="",min="",max="",a="",b="";con=DriverManager.getConnection("jdbc:odbc:4073","","");sql=con.createStatement(); //step2: 创建语句对象try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //step1: 装数据库驱动程序}catch(ClassNotFoundException e){ out.print(e);}try {num=request.getParameter("number");if(num!=null){num=new String(num.getBytes("ISO-8859-1"),"utf-8");condition="DELETE * FROM message Where logname = '"+num+"'";sql.execute(condition);}try{lu=request.getParameter("lunti");if(lu!=null){ lu=new String(lu.getBytes("ISO-8859-1"),"utf-8");condition="DELETE * FROM message Where title = '"+lu+"'";sql.execute(condition);}}catch(NumberFormatException e){out.print("format error");}try {a=request.getParameter("Min");min=a+" 00:00:00";b=request.getParameter("Max");max=b+" 24:00:00";if(min!=null && max!=null){condition="DELETE * FROM message Where time <= '"+max+"' AND time >= '"+min+"'";sql.execute(condition);}}catch(NumberFormatException e){out.print("format error");}condition="SELECT * FROM message";rs=sql.executeQuery(condition);//step3: 创建结果集对象并执行查询str.append("<table border=1>"); //制作表头str.append("<th width=100>"+"会员名");str.append("<th width=100>"+"主题");str.append("<th width=100>"+"微博");str.append("<th width=100>"+"时间");while(rs.next())//制作表体数据{ str.append("<tr>");str.append("<td>"+rs.getString(1)+"</td>");str.append("<td>"+rs.getString(2)+"</td>"); str.append("<td>"+rs.getString(3)+"</td>"); str.append("<td>"+rs.getString(4)+"</td>");str.append("</tr>");}str.append("<table border=1>");out.print(str);//输出结果con.close();}catch(SQLException e){ System.out.println(e);}catch(NumberFormatException e){out.print("format error");}%></Font></p><p><a href="index.jsp">返回</a></p></BODY></HTML>gchaxunFile.jsp<%@ page contentType="text/html;charset=utf-8" %><%@ page import="java.sql.*" %><HTML><style type="text/css"><!--.a {font-size: 18px;}.a {font-size: 24px;}.q {text-align: center;}.q {text-align: center;.q {text-align: center;}--></style><BODY><p><Font size=5><BODY bgcolor=lightblue ></Font></p><p class="a"> 微博查询系统</p><Font size=3><FORM action="" Method="post" class="q">查询会员的微博<BR>输入会员名:<Input type=text name="number"><Input type=submit name="g" value="确定"></Form><FORM action="" Method="post" class="q">查询会员主题的微博<BR>输入主题名:<Input type=text name="lunti"><Input type=submit name="b" value="确定"></Form><FORM action="" Method="post" class="q">查询某时间内的微博<BR> 时间在<Input type=text name="Min" size=10>至<Input type=text name="Max" size=10>之间<Input type=submit value="确定"></Form></Font><p><Font size=3><%StringBuffer str=new StringBuffer(); //用来存储查询结果Connection con;Statement sql;ResultSet rs;String lu="",condition="",num="",min="",max="",a="",b="";con=DriverManager.getConnection("jdbc:odbc:4073","","");sql=con.createStatement(); //step2: 创建语句对象try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //step1: 装数据库驱动程序}catch(ClassNotFoundException e){ out.print(e);}。