Hibernate综合运用内部留言本(二)
2017-12-01 19:08
281 查看
一 理解需求
二 根据需求文档,画出程序框架图
三 创建一个web项目
四 创建web层。
1 引入struts
2 web层开发
2.1 login.jsp
2.2 showMessage.jsp
2.3 LoginAction
2.4 GoMessageUiAction
2.5 UserForm
2.6 struts-config.xml
二 根据需求文档,画出程序框架图
三 创建一个web项目
四 创建web层。
1 引入struts
2 web层开发
2.1 login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> <html> <head> <title>My JSP 'login.jsp' starting page</title> </head> <body> <h1>用户登录</h1> <form action="/NoteBook/login.do?flag=login" method="post"> <table> <tr><td>用户id</td><td><input type="text" style="width: 100px" name="userid" /></td></tr> <tr><td>用户pw</td><td><input type="password" style="width: 100px" name="userpwd" /></td></tr> <tr><td><input type="submit" value="登录" /></td><td><input type="reset" value="重新填写" /></td></tr> </table> </form> </body> </html>
2.2 showMessage.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core"; prefix="c" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> <html> <head> <title>My JSP 'showMessage.jsp' starting page</title> </head> <body> <font size="6"><b><a href="#">发布信息</a></b></font> <font size="6"><b><a href="/NoteBook/login.do?flag=logout">退出系统</a></b></font><br/> 欢迎${userinfo.name } 留言信息: <table width="500px"> <tr><td>发送人</td><td>发送时间</td><td>接收人</td><td>信息内容</td></tr> <c:forEach items="${messageList}" var="message"> <tr> <td>${message.sender.name }</td> <td>${message.mesTime }</td> <td>${message.getter.name }</td> <td>${message.content }</td> </tr> </c:forEach> </table> </body> </html>
2.3 LoginAction
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.sina.struts.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import com.sina.domain.Users; import com.sina.service.imp.UsersServiceImp; import com.sina.service.inter.UsersServiceInter; import com.sina.struts.form.UserForm; /** * MyEclipse Struts * Creation date: 05-30-2011 * * XDoclet definition: * @struts.action parameter="flag" */ public class LoginAction extends DispatchAction { /* * Generated Methods */ /** * 这里我们响应login请求 */ public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub UserForm userForm=(UserForm)form; //使用service完成到数据库的验证 // UsersServiceImp usersService=new UsersServiceImp();//?这里直接使用对象,有定义耦合 web<-->业务层 //通过接口来调用. UsersServiceInter usersServiceInter= new UsersServiceImp(); //构建一个Users对象 Users user=new Users(); //String ->Integer user.setUserid(Integer.parseInt(userForm.getUserid())); user.setUserpwd(userForm.getUserpwd()); user=usersServiceInter.checkUser(user); if(user!=null){ //合法,将user对象放入session,后有用 request.getSession().setAttribute("userinfo", user); return mapping.findForward("loginok"); }else{ return mapping.findForward("goLoginUi"); } } /** * 这里我们响应logout请求 */ public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { //清空session request.getSession().invalidate(); return mapping.findForward("goLoginUi"); } }
2.4 GoMessageUiAction
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.sina.struts.action; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.actions.DispatchAction; import com.sina.domain.Message; import com.sina.domain.Users; import com.sina.service.imp.MessageServiceImp; import com.sina.service.inter.MessageServiceInter; /** * MyEclipse Struts * Creation date: 05-30-2011 * * XDoclet definition: * @struts.action parameter="flag" */ public class GoMessageUiAction extends DispatchAction { /* * Generated Methods */ /** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { // TODO Auto-generated method stub //去获取应该显示的留言信息,完成显示 //取出该用户收到的信息 MessageServiceInter messageServiceInter=new MessageServiceImp(); //取出当前用户 Users loginUser=(Users) request.getSession().getAttribute("userinfo"); List<Message> list=messageServiceInter.showMessage(loginUser); //现在应当list集合放到 session request, application? request request.setAttribute("messageList", list); return mapping.findForward("goMessageUi"); } }
2.5 UserForm
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.sina.struts.form; import org.apache.struts.action.ActionForm; /** * MyEclipse Struts * Creation date: 05-30-2011 * * XDoclet definition: * @struts.form name="userForm" */ public class UserForm extends ActionForm { private String userid; private String userpwd; public String getUserid() { return userid; } public void setUserid(String userid) { this.userid = userid; } public String getUserpwd() { return userpwd; } public void setUserpwd(String userpwd) { this.userpwd = userpwd; } }
2.6 struts-config.xml
相关文章推荐
- Hibernate综合运用内部留言本(一)
- Hibernate综合运用内部留言本(三)
- Hibernate综合运用内部留言本(四)
- Hibernate综合运用内部留言本(五)
- Hibernate综合运用内部留言本(六)
- 内部类综合运用 温室的运作(策略模式)
- QT5 OpenGL (六, 键盘事件, 开关灯,放大缩小综合运用)
- Hibernate面试题 --- Hibernate主键的生成策略(Oracle数据运用那种主键生成策略)
- struts+hibernate综合开发案例
- 书店管理系统---User模块.Dao层(JavaSE综合运用(一))
- HTML5 结构之美(3) - 结构标签综合运用
- JavaSE 练习对面向对象思想、单列集合、双列集合的综合运用 - 斗地主
- Linux网络编程综合运用之MiniFtp实现(七)
- Repeater嵌套,增删改查综合运用
- 第21回 测试用例设计方法的综合运用
- Hibernate 的内部执行流程
- Linux网络编程综合运用之MiniFtp实现(三)
- EHCache入门系列(三)–在Hibernate 中运用EHCache
- 综合运用三种对话框
- UVA12096,STL stack和set,Map的综合运用