《最新Web课程设计.doc》由会员分享,可在线阅读,更多相关《最新Web课程设计.doc(187页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateWeb课程设计Web课程设计Web课程设计课程设计报告书 设计题目 micro blog信息系统 专业班级 xxxxx 学号姓名 xxxxxxxxx 指导老师 xxxxxxx设计日期 xxxx 年x月x日 前言Micro blog信息系统主要是一个校园微博系统,在该系统中可以注册、登录,同时还分普通会员登录及管理员登录。通过登录后,可实现发布、查询、删除微博等各项功能
2、。关键字:信息系统 微博 登录系统分析1.设计目的:1综合应用java程序设计、WEB程序设计、数据库应用、计算机网络等知识设计和实现我校Micro Blog信息系统。2通过上述设计和实现,加深对java程序设计、WEB程序设计、数据库应用、计算机网络相关理论的理解,锻炼综合应用所学知识分析问题和解决问题的能力。3培养软件开发的团队协作精神。系统设计1.设计内容:(1)用户注册(2)用户登录(分一般用户和管理员)(3)某用户发布微博信息(4)浏览所有用户的微博信息(5)浏览指定用户的微博信息(6)查询某些用户或(且)某时间段或(且)某论题的微博信息。(7)删除某些用户或(且)某时间段或(且)某
3、论题的微博信息。(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,三张表
4、分别为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;
5、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
6、=,time=,title=,backNews; publicvoid setLogname(String name) logname=name; public String getLogname() returnlogname; publicvoid setTitle(String t) title=t; public String getTitle() returntitle; publicvoid setTime(String t) time=t; public String getTime() returntime; public String getMessage() returnm
7、essage; publicvoid setMessage(String m) message=m; public String getBackNews() returnbackNews; 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=
8、name; public String getLogname() returnlogname; publicvoid setQq(String q) qq=q; public String getQq() returnqq; publicvoid setPassword(String pw) password=pw; public String getPassword() returnpassword; publicvoid setEmail(String em) email=em; public String getEmail() returnemail; publicvoid setPho
9、ne(String ph) phone=ph; public String getPhone() returnphone; public String getBackNews() returnbackNews; publicvoid setBackNews(String s) backNews=s; ConditionQuery.javapackage mybean.data;import java.sql.*;public class ConditionQuery String logname ; StringBuffer queryResultBylogname; public Condi
10、tionQuery() 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 getQuery
11、ResultBylogname() 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 String uri=jdbc:sqlserver
12、:/127.0.0.1:1433;DatabaseName=factory; con=DriverManager.getConnection(jdbc:odbc:4073,); sql=con.createStatement(); rs=sql.executeQuery(condition); str.append(); str.append(+logname); str.append(+title); str.append(+message); str.append(+time); while(rs.next() str.append(); str.append(+rs.getString(
13、1)+); str.append(+rs.getString(2)+); str.append(+rs.getString(3)+); str.append(+rs.getString(4)+); str.append(); str.append(); con.close(); catch(SQLException e) System.out.println(e); return str; HandleAdmin.javapackage myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;impor
14、t 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.getByte
15、s(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; Login loginBean=null; String backNews=; HttpSession session=request.getSession(true);
16、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(pass
17、word).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
18、.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.setBa
19、ckNews(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);
20、loginBean.setSuccess(false); loginBean.setLogname(logname); loginBean.setPassword(password); con.close(); catch(SQLException exp) backNews=+exp; loginBean.setBackNews(backNews); loginBean.setSuccess(false); RequestDispatcher dispatcher=request.getRequestDispatcher(showAdminMess.jsp); dispatcher.forw
21、ard(request, response); public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException doPost(request,response); HandleLogin.javapackage myservlet.control;import mybean.data.*;import java.sql.*;import java.io.*;import javax.servlet.*;import javax.servl
22、et.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); cat
23、ch(Exception ee) return s; public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException Connection con; PreparedStatement sql; Login loginBean=null; String backNews=; HttpSession session=request.getSession(true); try loginBean=(Login)session.getAttr
24、ibute(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.g
25、etSuccess(); 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,); Str
26、ing 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
27、(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.s
28、etLogname(logname); loginBean.setPassword(password); con.close(); catch(SQLException exp) backNews=+exp; loginBean.setBackNews(backNews); loginBean.setSuccess(false); RequestDispatcher dispatcher=request.getRequestDispatcher(showLoginMess.jsp); dispatcher.forward(request, response); public void doGe
29、t(HttpServletRequest request,HttpServletResponse response) 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.*;
30、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
31、=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); /获取用户登录时的Javabean boolean ok=true; if(login=nul
32、l) 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.getAttri
33、bute(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 SimpleDateF
34、ormat(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