异常控制和处理.doc

上传人:hw****26 文档编号:4204899 上传时间:2019-10-04 格式:DOC 页数:11 大小:70KB
下载 相关 举报
异常控制和处理.doc_第1页
第1页 / 共11页
异常控制和处理.doc_第2页
第2页 / 共11页
异常控制和处理.doc_第3页
第3页 / 共11页
异常控制和处理.doc_第4页
第4页 / 共11页
异常控制和处理.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

1、public class ForumExceptionHandler extends ExceptionHandler Logger log = Logger.getLogger(getClass(); Override public ActionForward execute(Exception exception, ExceptionConfig config, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletExc

2、eption request.setAttribute(“exception“, exception); log.info(exception, exception); if (exception instanceof AccountException) return new ActionForward(“login“, “/form/person/login.jsp“, false); return new ActionForward(“exception“, “/form/exception.jsp“, false); public abstract class ForumAction e

3、xtends DispatchAction protected Log log = LogFactory.getLog(getClass(); Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception ForumForm forumForm = (ForumForm) form; forumForm.setTitle(“轻量级 Java EE 论坛程

4、序“); if (forumForm.getAction() = null | forumForm.getAction().trim().length() = 0) return this.list(mapping, form, request, response); return super.execute(mapping, form, request, response); public abstract ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpSe

5、rvletResponse response) throws Exception; public class PersonAction extends ForumAction private IPersonService personService; /* * 默认方法 返回到注册页面 */ public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) / PersonForm personForm = (Pe

6、rsonForm) form; / / List personList = personService.list(“ from Person “, 0, 100, / null); / / request.setAttribute(“personList“, personList); / / return mapping.findForward(“list“); return this.initAdd(mapping, form, request, response); /* * 显示注册页面 * param mapping * param form * param request * par

7、am response * return */ public ActionForward initAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户注册“); return mapping.findForward(“add“); /* * 显示登录页面 * param mapping * param form *

8、 param request * param response * return */ public ActionForward initLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户登录“); return new ActionForward(“login“, “/form/person/login.j

9、sp“, false); /* * 注册 * param mapping * param form * param request * param response * return */ public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户注册“); Person per

10、son = personForm.getPerson(); person.setIpCreated(request.getRemoteAddr(); person.setIpLastActived(request.getRemoteAddr(); person.setDateCreated(new Date(); person.setDateLastActived(new Date(); if (person.getAccount() = null | person.getAccount().trim().length() = 0) request.setAttribute(“message“

11、, “请输入帐号“); return this.initAdd(mapping, form, request, response); if (person.getPassword() = null | person.getPassword().trim().length() = 0 | !person.getPassword().equals(personForm.getPassword() request.setAttribute(“message“, “密码不一致“); return this.initAdd(mapping, form, request, response); try p

12、ersonService.create(person); PersonUtil.setPersonInf(request, response, person); request.setAttribute(“message“, “注册成功“); return new ActionForward(“success“, “/form/person/success.jsp“, false); catch (Exception e) request.setAttribute(“message“, “注册失败,原因:“ + e.getMessage(); return this.initAdd(mappi

13、ng, form, request, response); /* * 登录 * param mapping * param form * param request * param response * return * throws Exception */ public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception PersonForm personForm = (Pe

14、rsonForm) form; personForm.setTitle(“用户登录“); Person person = personService.getPerson(personForm.getPerson() .getAccount(), personForm.getPerson().getPassword(); if (person = null) throw new AccountException(“用户名密码错误“); PersonUtil.setPersonInf(request, response, person); person.setIpLastActived(reque

15、st.getRemoteAddr(); person.setDateLastActived(new Date(); personService.save(person); request.setAttribute(“message“, “欢迎回来“); return new ActionForward(“success“, “/form/person/success.jsp“, false); /* * 注销 * param mapping * param form * param request * param response * return * throws Exception */

16、public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户注销“); request.getSession(true).setAttribute(PersonUtil.PERSON_INFO, null); return new Actio

17、nForward(“success“, “/“, true); /* * 查看用户信息 * param mapping * param form * param request * param response * return * throws Exception */ public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception PersonForm personForm

18、= (PersonForm) form; personForm.setTitle(“查看用户资料“); Person person = personService.find(Person.class, personForm.getPerson() .getId(); request.setAttribute(“person“, person); return new ActionForward(“view“, “/form/person/viewPerson.jsp“, false); public IPersonService getPersonService() return person

19、Service; public void setPersonService(IPersonService personService) this.personService = personService; public class PersonAction extends ForumAction private IPersonService personService; /* * 默认方法 返回到注册页面 */ public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest reques

20、t, HttpServletResponse response) / PersonForm personForm = (PersonForm) form; / / List personList = personService.list(“ from Person “, 0, 100, / null); / / request.setAttribute(“personList“, personList); / / return mapping.findForward(“list“); return this.initAdd(mapping, form, request, response);

21、/* * 显示注册页面 * param mapping * param form * param request * param response * return */ public ActionForward initAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户注册“); return mapping.

22、findForward(“add“); /* * 显示登录页面 * param mapping * param form * param request * param response * return */ public ActionForward initLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) PersonForm personForm = (PersonForm) form; personForm.setTitle(“用

23、户登录“); return new ActionForward(“login“, “/form/person/login.jsp“, false); /* * 注册 * param mapping * param form * param request * param response * return */ public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) PersonForm personFor

24、m = (PersonForm) form; personForm.setTitle(“用户注册“); Person person = personForm.getPerson(); person.setIpCreated(request.getRemoteAddr(); person.setIpLastActived(request.getRemoteAddr(); person.setDateCreated(new Date(); person.setDateLastActived(new Date(); if (person.getAccount() = null | person.ge

25、tAccount().trim().length() = 0) request.setAttribute(“message“, “请输入帐号“); return this.initAdd(mapping, form, request, response); if (person.getPassword() = null | person.getPassword().trim().length() = 0 | !person.getPassword().equals(personForm.getPassword() request.setAttribute(“message“, “密码不一致“)

26、; return this.initAdd(mapping, form, request, response); try personService.create(person); PersonUtil.setPersonInf(request, response, person); request.setAttribute(“message“, “注册成功“); return new ActionForward(“success“, “/form/person/success.jsp“, false); catch (Exception e) request.setAttribute(“me

27、ssage“, “注册失败,原因:“ + e.getMessage(); return this.initAdd(mapping, form, request, response); /* * 登录 * param mapping * param form * param request * param response * return * throws Exception */ public ActionForward login(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletR

28、esponse response) throws Exception PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户登录“); Person person = personService.getPerson(personForm.getPerson() .getAccount(), personForm.getPerson().getPassword(); if (person = null) throw new AccountException(“用户名密码错误“); PersonUtil.setPerso

29、nInf(request, response, person); person.setIpLastActived(request.getRemoteAddr(); person.setDateLastActived(new Date(); personService.save(person); request.setAttribute(“message“, “欢迎回来“); return new ActionForward(“success“, “/form/person/success.jsp“, false); /* * 注销 * param mapping * param form *

30、param request * param response * return * throws Exception */ public ActionForward logout(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception PersonForm personForm = (PersonForm) form; personForm.setTitle(“用户注销“); request.getSession(true

31、).setAttribute(PersonUtil.PERSON_INFO, null); return new ActionForward(“success“, “/“, true); /* * 查看用户信息 * param mapping * param form * param request * param response * return * throws Exception */ public ActionForward view(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpSer

32、vletResponse response) throws Exception PersonForm personForm = (PersonForm) form; personForm.setTitle(“查看用户资料“); Person person = personService.find(Person.class, personForm.getPerson() .getId(); request.setAttribute(“person“, person); return new ActionForward(“view“, “/form/person/viewPerson.jsp“, false); public IPersonService getPersonService() return personService; public void setPersonService(IPersonService personService) this.personService = personService;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 实用文档资料库 > 策划方案

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。