- 创建拦截器
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>
原文地址:https://www.cnblogs.com/batj/p/9118572.html
时间: 2024-10-29 19:09:01