Struts2中攔截器
阿新 • • 發佈:2018-05-31
esp version dex config extends 過程 void ret success
- 創建攔截器
package com.zhangpn.Intercepor; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.Interceptor; public class PermissionIntercepor implements Interceptor{ @Override public void destroy() { // TODO Auto-generated method stub } @Override public void init() { // TODO Auto-generated method stub } @Override public String intercept(ActionInvocation arg0) throws Exception { // TODO Auto-generated method stub return null; } }
intercept方法為攔截過程。
- 配置文件:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.multipart.saveDir" value="/tmp"/> <package name="default" namespace="/" extends="struts-default"> <interceptors> <interceptor name="PERMIT" class="com.zhangpn.Intercepor.PermissionIntercepor"></interceptor> </interceptors> <action name="index" class="com.zhangpn.struts2.Uploadfile"> <interceptor-ref name="PERMIT"/> <result name="success">welcome.jsp</result> <result name="error">error.jsp</result> </action> </package> </struts>
Struts2中攔截器