Mvc中的视图,如何使用@Fail?
有时想故意转到@Fail来处理,如何激活它呢? 激活他后,又如何进行后续的操作?
8 回复
我这样用的,直接程序exception,崩溃了,没有转到@Fail
@At("/mycarbnet")
@Ok("jsp:/book/booklistmine.jsp")
@Fail("jsp:/exception/exception.jsp")
public Map<String, Object> knownlegeIndex(HttpServletRequest request,
HttpServletResponse response) throws Exception {
int userid=StringUtil.getInt(request, "userid", 0);
int pagesize=StringUtil.getInt(request, "pagesize", 10);
int page=StringUtil.getInt(request, "page", 1);
if(userid<=0){
ViewMsg vm=new ViewMsg();
vm.setOk(false);
vm.setMsg("未登录。");
throw new Exception("未登录。");
}
....
@xiciliu 自定义过动作链?某个处理类把异常给吃了?
加上catch,又不到@Fail了,后台的异常trace信息有办法消除吗?
@At("/mycarbnet")
@Ok("jsp:/book/booklistmine.jsp")
@Fail("jsp:/exception/exception.jsp")
public Map<String, Object> bookMine(HttpServletRequest request,
HttpServletResponse response) {
int userid=StringUtil.getInt(request, "userid", 0);
int pagesize=StringUtil.getInt(request, "pagesize", 10);
int page=StringUtil.getInt(request, "page", 1);
if(userid<=0){
ViewMsg vm=new ViewMsg();
vm.setOk(false);
vm.setMsg("未登录。");
try {
throw new Exception("未登录。");
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
}
@xiciliu 要全清的话可以配log4j
但我觉得你返回一个JspView比抛异常好吧,抛异常一般属于"意外"
@wendal 确是如此。那么就用不上Fail了
添加回复
请先登陆