先写一个过滤器类继承Interceptor
//
Source file: F:/java/Oil/src/com/xj/tools/UserAccessInterceptor.java
package com.xj.tools;
import java.util.Map;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
import com.xj.model.User;
public class UserAccessInterceptor implements Interceptor {
public static final String index = "INDEX";
/**
* @roseuid 462436220251
*/
public UserAccessInterceptor() {
}
public void destroy() {
}
public void init() {
}
public String intercept(ActionInvocation arg0) throws Exception {
return "index";
/***********************************************************************
* Map session = ActionContext.getContext().getSession(); if
* (session.get("user") == null) { return index; } else if (((User)
* session.get("user")).getUsername() == null) return index; return
* arg0.invoke();
**********************************************************************/
}
}
package com.xj.tools;
import java.util.Map;
import com.opensymphony.xwork.ActionContext;
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.Interceptor;
import com.xj.model.User;
public class UserAccessInterceptor implements Interceptor {
public static final String index = "INDEX";
/**
* @roseuid 462436220251
*/
public UserAccessInterceptor() {
}
public void destroy() {
}
public void init() {
}
public String intercept(ActionInvocation arg0) throws Exception {
return "index";
/***********************************************************************
* Map session = ActionContext.getContext().getSession(); if
* (session.get("user") == null) { return index; } else if (((User)
* session.get("user")).getUsername() == null) return index; return
* arg0.invoke();
**********************************************************************/
}
}
然后再写一个Webwork的配置文件xwork-losbgm-default.xml
<?
xml version
=
"
1.0
"
encoding
=
"
UTF-8
"
?>
<! DOCTYPE xwork PUBLIC " -//OpenSymphony Group//XWork 1.1.1//EN "
" http://www.opensymphony.com/xwork/xwork-1.1.1.dtd " >
< xwork >
< include file = " webwork-default.xml " />
< package name = " xwork-losbgm-default " extends = " webwork-default " >
< interceptors >
< interceptor name = " employeeAccessInterceptor "
class = " com.xj.tools.UserAccessInterceptor " >
</ interceptor >
< interceptor - stack name = " losbgmStack " >
< interceptor - ref name = " employeeAccessInterceptor " ></ interceptor - ref >
< interceptor - ref name = " defaultStack " />
</ interceptor - stack >
</ interceptors >
< default - interceptor - ref name = " losbgmStack " ></ default - interceptor - ref >
< global - results >
< result name = " index " type = " redirect " >/ index.jsp </ result >
</ global - results >
</ package >
</ xwork >
<! DOCTYPE xwork PUBLIC " -//OpenSymphony Group//XWork 1.1.1//EN "
" http://www.opensymphony.com/xwork/xwork-1.1.1.dtd " >
< xwork >
< include file = " webwork-default.xml " />
< package name = " xwork-losbgm-default " extends = " webwork-default " >
< interceptors >
< interceptor name = " employeeAccessInterceptor "
class = " com.xj.tools.UserAccessInterceptor " >
</ interceptor >
< interceptor - stack name = " losbgmStack " >
< interceptor - ref name = " employeeAccessInterceptor " ></ interceptor - ref >
< interceptor - ref name = " defaultStack " />
</ interceptor - stack >
</ interceptors >
< default - interceptor - ref name = " losbgmStack " ></ default - interceptor - ref >
< global - results >
< result name = " index " type = " redirect " >/ index.jsp </ result >
</ global - results >
</ package >
</ xwork >
接着在要实现拦截器的Webwork的配置文件的Package中继承上面的配置文件就可以了
<
include
file
="xwork-losbgm-default.xml"
/>
< package name ="showOilLib" extends ="xwork-losbgm-default" >
< action name ="showOilLibAction"
class ="com.xj.action.Oil.ShowOilLibAction" >
< result name ="success" > main.jsp </ result >
</ action >
</ package >
< package name ="showOilLib" extends ="xwork-losbgm-default" >
< action name ="showOilLibAction"
class ="com.xj.action.Oil.ShowOilLibAction" >
< result name ="success" > main.jsp </ result >
</ action >
</ package >