補上自定義的錯誤攔截器代碼和國際化資源代碼java
package com.hello.web; /** * 自定義攔截器例子 * 攔截器是單例的 * */ import java.util.Map; import org.apache.struts2.dispatcher.ServletDispatcherResult; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.Result; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class ErrorInterceptor extends AbstractInterceptor { private static final long serialVersionUID = -7370956658036991526L; private Logger logger = LoggerFactory.getLogger(ErrorInterceptor.class); @Override public String intercept(ActionInvocation invocation) throws Exception { // TODO Auto-generated method stub try { logger.debug("begin-------------------------------"); logger.debug("ErrorInterceptor實例:"+this.toString()); //找到運行的Action對象,並打印其類名 //logger.debug("Action:"+invocation.getAction().getClass().getName()); logger.debug("Action:"+invocation.getAction().getClass()); //找到運行的ActionProxy對象,並打印其要運行的方法名 logger.debug("Method:"+invocation.getProxy().getMethod()); //找到此次請求的request中的parameter參數,並打印 Map<String, Object> params = invocation.getInvocationContext().getParameters(); for (String key:params.keySet()){ Object obj = params.get(key); if(obj instanceof String[]){ String[] arr = (String[]) obj; logger.debug("Param:"+key); for (String value:arr){ logger.debug(value); } } } //運行後續的攔截器、Action和Result String resultCode = invocation.invoke(); logger.debug("resultCode:"+resultCode); //在Action和Result運行以後,獲得Result對象 //而且能夠強制轉換成ServletDispatcherResult,打印其下一個JSP的位置 Result rresult = invocation.getResult(); if (rresult instanceof ServletDispatcherResult){ ServletDispatcherResult result = (ServletDispatcherResult) rresult; logger.debug("JSP:"+result.getLastFinalLocation()); } logger.debug("end-------------------------------"); return resultCode; }catch(Exception e){ logger.error("攔截器異常:",e); return "500"; } } }
國際化文件web
userIdNotNull=\u7528\u6237\u540D\u4E0D\u80FD\u4E3A\u7A7A\uFF01 passwordlengthErrMsg=\u5BC6\u7801\u957F\u5EA6\u9700\u5927\u4E8E6\u4F4D\uFF01 passwordNotNull=\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A\uFF01 #file upload struts.messages.error.content.type.not.allowed=\u4E0A\u4F20\u6587\u4EF6\u53EA\u80FD\u4E3AJPG,PNG,GIF,TXT\u7C7B\u578B\uFF01 struts.messages.error.file.too.large=\u6700\u591A\u53EA\u80FD\u4E0A\u4F201M\u5927\u5C0F\u7684\u6587\u4EF6\uFF01 struts.messages.upload.error.SizeLimitExceededException=\u6700\u5927\u53EA\u5141\u8BB8\u4E0A\u4F20\: {0} Byte \u5F53\u524D\u6587\u4EF6\u5927\u5C0F\: {1} Byte\!
完整的例子,後續打個包傳上來
apache