在web.xml ,定义首页位置:
[code="xml"]
index.jsp
[/code]
并配置了一个filter,用于过滤对jsp的直接访问.
[code="xml"]
indexfilter
com.prodinfo.filter.IndexFilter
indexfilter
/index.jsp
[/code]
[code="java"]
......
public class IndexFilter implements Filter {
......
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest re = (HttpServletRequest) request;
HttpSession session = re.getSession();
//redirect to action
request.getRequestDispatcher("loadindex.action?id=xxx").forward(
request, response);
System.out.println("i am filter");
}
......
}
[/code]
struts.xml中配置了interceptor,拦截用户的请求,在action执行之前,load页面信息,然后继续.
[code="xml"]
class="loadHeaderFooter">
method="loadCompanyInfo">
/index.jsp
[/code]
[code="java"]
......
public String intercept(ActionInvocation invocation) throws Exception {
//System.out.println("Before Action");
//get header & footer infomation
List result = ci.getHeaderFooter("xxx");
......
System.out.println("i am interceptor");
final String res = invocation.invoke();
//System.out.println("After Action");
return res;
}
......
[/code]
我理解的执行顺序是()index.jsp->(filter)"loadindex.action?id=xxx"->(interceptor)"loadHeaderFooter"->(Action)"loadindex"->(jsp)index.jsp
可是现在执行的顺序是先interceptor再filter,程序运行打印结果是:
i am interceptor
loading company info of null
i am filter
请问我该在哪里配置filter 和 interceptor的顺序呢? 谢谢!
[b]问题补充:[/b]
谢谢 蔡华江 的回复.
即是说我应该从web.xml里filter的位置来下手找我的问题的原因?
[b]问题补充:[/b]
去掉了interceptor,发现还是先执行的action再进的filter. Struts2的执行顺序一定是先action再filter? 已经把FilterDispatcher放到web.xml最上面了.