0
回答
struts2中异常的处理
终于搞明白,存储TCO原来是这样算的>>>   

    如下在web.xml中配置了异常界面

  <error-page>
 <exception-type>java.lang.Exception</exception-type>
  <location>/error.jsp</location>
 </error-page>
 <!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->
 <error-page>
  <exception-type>java.lang.NullPointerException</exception-type>
  <location>/error.jsp</location>
 </error-page>
 <error-page>
  <exception-type>javax.servlet.ServletException</exception-type>
  <location>/error.jsp</location>
 </error-page>

struts2中action如下  如果使web.xml配置的异常界面有效,就必须在Action中抛出异常,请问还有什么好的方法吗?在service抛出异常是不是更好?但是如果在service中跑出异常,action中用try catch出现了异常不throw那就出现了错误也不会跳转到错误界面,好纠结,大家是怎么处理的?

@Action(value = "/ReinsurerAction-listReinsurer", results = {@Result(name = SUCCESS, location = "/view/reinsurer/listReinsurer.jsp")})
 public String listReinsurer() throws Exception{
  try {
   list = reinsurerService.listReinsurer(reinsurer,page);
   System.out.println("list.size()="+list.size());
      for(int i = 0;i < list.size();i++){
       Reinsurer er = (Reinsurer) list.get(i);
       System.out.println("代码="+er.getRierCode());
       System.out.println("名称="+er.getRierName());
      }
  } catch (Exception e) {
   logger.error("ReinsurerAction-ListReinsurer occur Excepiton", e);
   throw new Exception(e);
  }
  return SUCCESS;
 }

<无标签>
举报
javaSir
发帖于3年前 0回/121阅
顶部