Javaweb项目编写-----留言板的设计指导教师:庄凯小组成员:hx20090412 田磊hx20090429 宋昭辉hx20090430孔席超1.归纳项目的功能(宏观)--UML的UseCase(用例图)在本项目中,共有8个模块,小组成员分配如下:孔席超:注册,登录,浏览;田磊:发表主题,分页查看;宋昭辉:删除主题,修改主题,发表评论。
2.根据用例图,确定功能所需要的信息(确定数据字典)信息数据类型用户编号Uid int用户名username String性别sex String密码Password String昵称Lovername String创建时间Regtime Timestape信息数据类型主题编号tid Int主题名称Tname String主题内容Tcontext Text发表时间Ttime TimestapeContext表信息数据类型评论内容Ccontext Text评论时间Ctime Timestape 评论编号cid Int数据建模数据模型之间的关系将其转换成为真实的表生成sql脚本/*==================================================*//* DBMS name: MySQL 5.0 *//* Created on: 2010/11/28 14:48:07 *//*===================================================*/drop table if exists Context; /如果存在context表将它删除drop table if exists Topic; //如果存在topic表将它删除drop table if exists User; //如果存在user表将它删除/*======================================================*//* Table: Context *//*======================================================*/create table Context(cid int auto_increment not null, //定义整形变量cid,非空tid int, //定义整形变量tiduid int, //定义整型变量uidccontext text not null, //定义文本区ccontext,非空ctime timestamp not null, //定义一个时间戳,非空primary key (cid) //主键为cid);/*====================================================*//* Table: Topic *//*===================================================*/create table Topic(tid int auto_increment not null, //定义整形变量tid,非空uid int, //定义整型变量uidtname varchar(20) not null,//定义字符串tname,非空tcontext text not null, //定义文本区,非空ttime timestamp not null, //定义一个时间戳,非空primary key (tid) //主键为tid);/*====================================================*//* Table: User *//*====================================================*/create table User(uid int auto_increment not null, //定义整形变量uid,非空username varchar(10) not null,//定义字符串username,非空sex varchar(4) not null, //定义字符串sex,非空password varchar(20) not null, //定义字符串password,非空lovername varchar(10) not null, //定义字符串password,非空regtime timestamp not null, //定义一个时间戳,非空primary key (uid) //主键为uid);3.根据用例图创建时序和动作图以下注册、登录模块为孔席超制作:注册模块:登录模块:以下发表主题模块为田磊制作:发表主题模块:以下删除主题、修改主题模块为宋昭辉制作:删除主题模块:修改主题模块:4.资源(整合)视图级别 :index.jsp login.jsp register.jsp addTopic.jsp 控制级别: UserAction.java TopAction.java模型级别 : DAO.java数据库控制:DBHander.java5.类图6.程序功能说明:程序部分代码及功能的截图如下:以下模块为孔席超设计编写:注册模块:后台验证有无重复信息代码String sql="select count(*) from user where username=? and lovername=?"; PreparedStatement ps=conn.prepareStatement(sql);ps.setString(1, user.getUsername());ps.setString(2, user.getLovername());ResultSet rs = ps.executeQuery();添加新的注册的信息sql="insert into user values (null,?,?,?,?,sysdate())";ps=conn.prepareStatement(sql);ps.setString(1, user.getUsername());ps.setString(2, user.getSex());ps.setString(3, user.getLovername());ps.setString(4, user.getPassword());ps.executeUpdate();汉字转码:String username = request.getParameter("username");username=new String(username.getBytes("ISO8859_1"),"utf-8"); String lovername = request.getParameter("lovername");lovername=new String(lovername.getBytes("ISO8859_1"),"utf-8"); String sex = request.getParameter("sex");sex=new String(sex.getBytes("ISO8859_1"),"utf-8");String password = request.getParameter("password");登录模块:在数据库中进行查询的验证String sql = "select password,uid from user where username=?"; 浏览模块:创建查询的句柄语句, 查询topic表中的信息:String sql = "select tid ,uid ,tname,tcontext,ttime from topic"; PreparedStatement ps = conn.prepareStatement(sql);ResultSet rs = ps.executeQuery();以下模块为田磊设计编写:发表主题模块:向数据库添加信息代码:String sql="insert into topic values (null,null,?,?,sysdate())"; PreparedStatement ps=conn.prepareStatement(sql);ps.setString(1, topic.getTname());ps.setString(2, topic.getTcontext());ps.executeUpdate();汉字转码:String tname = request.getParameter("tname");tname=new String(tname.getBytes("ISO-8859-1"),"utf-8");String context = request.getParameter("tcontext");context=new String(context.getBytes("ISO-8859-1"),"utf-8"); String id = request.getParameter("tid").trim();分页查看模块:以下模块为宋昭辉设计编写:删除主题模块:删除前:删除前两个主题:从数据库中删除信息部分代码:String sql = "delete from topic where tid=?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, id);ps.execute();要删除的主题的编号获取:String tid=request.getParameter("tid");Integer id=Integer.parseInt(tid);DAO dao=new DAO();Topic topic = dao.delTopicById(id);获取要删除的主题:request.setAttribute("topic", topic);修改主题模块:修改前:对第一条主题进行修改:修改完成:修改模块的部分代码:String sql = "update topic set tname= ? , tcontext= ? where tid=? "; 要修改的主题的编号获取:String tid=request.getParameter("tid");Integer id=Integer.parseInt(tid);System.out.println("tid "+id);DAO dao=new DAO();Topic topic = dao.getTopicById(id);获取要修改的主题:request.setAttribute("topic", topic);7.心得体会孔席超:在本次项目中我主要负责的是注册以及登陆模块。