标签:属性 元素 对象 exe setname servlet 默认 image ges
2. 自动异常处理机制
1 <action path="/login" type="com.jialin.LoginAction" name="userForm" scope="request" validate="true" attribute="uf" input="/index.jsp"> 2 <exception key="login.user.not.found" type="com.jialin.UserNotFoundException" /> 3 <exception key="login.password.error" type="com.jialin.PasswordErrorException" path="/LoginFail.jsp" /> 4 5 </action>
该Exception只对当前action起作用,也可以配置全局exception
1 <global-exceptions> 2 <exception key="login.user.not.found" type="com.jialin.UserNotFoundException" /> 3 <exception key="login.password.error" type="com.jialin.PasswordErrorException" path="/LoginFail.jsp" /> 4 </global-exceptions>
2)哪个优先?——就近原则
即可将其异常对应的错误消息文本进行显示
1 ** 2 * 登录action 3 * 4 * @author jialin 作用:取得表单数据,调用model层业务逻辑,返回转向信息 5 */ 6 public class LoginAction extends Action { 7 8 @Override 9 public ActionForward execute(ActionMapping mapping, ActionForm form, 10 HttpServletRequest request, HttpServletResponse response) 11 throws Exception { 12 UserActionForm userForm = (UserActionForm) form; 13 String userName = userForm.getName(); 14 int password = userForm.getPassword(); 15 16 UserManage userManage = new UserManage(); 17 User user = new User(); 18 user.setName(userName); 19 user.setPassword(password); 20 //这里不再有trycatch语句 21 userManage.ValidateUser(user); 22 return mapping.findForward("success"); 23 24 } 25 26 } 27 28 29 <span style="font-family:Arial;BACKGROUND-COLOR: #ffffff"></span>
二、就近原则
标签:属性 元素 对象 exe setname servlet 默认 image ges
原文地址:http://www.cnblogs.com/lesleysbw/p/6252591.html