请教大家:
我写了个filter,内容如下:
public class LimitFilter implements Filter { private FilterConfig config;
public void destroy() {
this.config = null;
}
public void init(FilterConfig config) throws ServletException {
this.config = config;
}
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {

System.out.println("------begin--------");
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
                chain.doFilter(request, response);
}
web.xml关键部分如下:
       <filter>
 <filter-name>limitFilter</filter-name>
 <filter-class>com.chinawidth.card.filter.LimitFilter</filter-class>
       </filter>
<filter-mapping>
<filter-name>limitFilter</filter-name>
<url-pattern>/login.action</url-pattern>
</filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
index.jsp页面:
<%
    response.sendRedirect("login.action");
%>
程序运行,没有打印出:------begin--------
如果把<url-pattern>/login.action</url-pattern>改为:<url-pattern>/*</url-pattern>就有打印出
请问只针对login.action如何让该filter被调用?

解决方案 »

  1.   

    过滤器配置希望被过滤的请求路径 /*是全部请求都被过滤 你可以写个别的路径 比如login/login.do
      

  2.   

    你请求login.action后地址栏里显示的是什么路径,从项目名称开始的字符串和/login.action匹配不匹配 
      

  3.   

    地址栏url如下:
    http://localhost:6220/card/login.action在index.jsp里:
    <%
       response.sendRedirect("login.action");
    %>
    我url输入:http://localhost:6220/card,将转向login.action。url为:http://localhost:6220/card/login.action。如果我改成:
    <%
      request.getRequestDispatcher("login.action").forward(request,response);
    %>
    就报404找不到该action错误。换成:/login.action也不行。
      

  4.   

    我也遇到过此类问题,我觉得是Struts的问题,我换成Servlet就没问题。
    期待告诉解决问题!观望!
      

  5.   

    试试完整urlresponse.sendRedirect("http://localhost:6220/card/login.action"); 
      

  6.   

    index.jsp页面:
    <%
        response.sendRedirect("login.action");
    %> 
    用submit去试一下
    <form action="/login.action" method="post">              <input type="submit" name="submit" value="提交" >
            
          </form>如果,可以那是请求转发路径有问题..
      

  7.   

    额,看你的完整的Web.xml
    应该是
    response.sendRedirect("http://localhost:6220/card/login.do"); 吧。