0

我正在使用 Tomcat 6.0.36,欢迎页面是 /Login.jsp 我有一个过滤器,以便它可以为移动设备显示不同的登录页面。它适用于 URL mywebsite.com/Login.jsp,但当 URL 只是 mywebsite.com 时,过滤器会被绕过。

有没有办法强制它执行?

我找到了这个页面,但在我的情况下它不起作用:

如何在 Tomcat 的 web.xml 中为欢迎文件映射过滤器?

谢谢

我的 web.xml:

<welcome-file-list>
    <welcome-file>/Login.jsp</welcome-file>
</welcome-file-list>
...
<filter>
    <display-name>LoginPageFilter</display-name>
    <filter-name>LoginPageFilter</filter-name>
    <filter-class>filters.LoginPageFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>LoginPageFilter</filter-name>
    <url-pattern>/Login.jsp</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

过滤器 - 我已将其删除并迅速将其重新组合在一起

public class LoginPageFilter implements Filter 
{
    public LoginPageFilter()  { }

    public void init ( FilterConfig fConfig ) throws ServletException { }

    public void doFilter ( ServletRequest request, ServletResponse response,
        FilterChain chain ) throws IOException, 
    ServletException 
    {
        System.out.println ( "Filter being executed" );
        chain.doFilter(request, response);
    }

    public void destroy() { }
}

如果网址是

http://localhost:8080/gymfit/Login.jsp

然后将消息打印到控制台。

当 URL 是

http://localhost:8080/gymfit/

显示相同的页面,但消息未打印到控制台

4

1 回答 1

2

看看这一行,这意味着只有对“/Login.jsp”的请求才会执行过滤器

    <url-pattern>/Login.jsp</url-pattern>

如果要将此过滤器应用于所有路径,请将配置更改为:

    <url-pattern>/*</url-pattern>
于 2013-05-09T09:38:30.363 回答