在Struts2 上面写的一个将JSP全部转移到WEB-INF下的拦截器,以下是具体代码和配置
package com.stockvote.interceptor;



import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.interceptor.Interceptor;


public class WebInfInterceptor implements Interceptor ...{
private static String PathPrefix = "/WEB-INF/";
private static final String LOCATION = "location";

public void destroy() ...{

}


public void init() ...{

if (PathPrefix.endsWith("/")) ...{
PathPrefix = PathPrefix.substring(0, PathPrefix.length() - 1);
}
}


public String intercept(ActionInvocation arg0) throws Exception ...{

Map map = arg0.getProxy().getConfig().getResults();


for (java.util.Iterator iter = map.values().iterator(); iter.hasNext();) ...{
ResultConfig rcg = (ResultConfig) iter.next();
transferLocation(rcg);
}

return arg0.invoke();
}


public void transferLocation(ResultConfig rcg) ...{

Map map = rcg.getParams();


if (!map.containsKey(LOCATION)) ...{
return;
}

// ////////////////////
String location = (String) map.get(LOCATION);


if (location.startsWith(PathPrefix)) ...{
return;
}


if (!location.startsWith("/")) ...{
location = "/" + location;
}

location = PathPrefix + location;

map.put(LOCATION, location);
}
}
<interceptor name="WebInfoPath" class="com.stockvote.interceptor.WebInfointerceptor"></interceptor>
<interceptor-stack name="defaultStack1">
<!--interceptor-ref name="log"></interceptor-ref!-->
<interceptor-ref name="defaultStack"></interceptor-ref>
<interceptor-ref name="WebInfoPath"></interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultStack1"></default-interceptor-ref>







































































下面是xml配置










