Tomcat 在执行 jsp 过滤器之前显示欢迎页面 [英] Tomcat displaying welcome-page before filter for jsp is executed

查看:60
本文介绍了Tomcat 在执行 jsp 过滤器之前显示欢迎页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Tomcat 6.0.36 and the welcome-page is /Login.jsp I have a filter in place so that it can display a different login page for mobile devices. It works with URL mywebsite.com/Login.jsp, but the filter is bypassed when the URL is just mywebsite.com.

有没有办法强制它执行?

Is there a way to force it to execute?

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

I have found this page but it doesn't work in my case:

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

谢谢

我的 web.xml:

My 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>

过滤器 - 我已经删除了它并迅速将其重新组合起来

The filter - I had deleted it and put one quickly back together

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

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

then the message is printed to the console.

当 URL 为

http://localhost:8080/gymfit/

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

the same page is displayed but the message is not printed out to the console

推荐答案

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

look at this line, this means only the request to '/Login.jsp' will the filter being executed

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

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

if you want to apply this filter to all the path, change the config to:

    <url-pattern>/*</url-pattern>

这篇关于Tomcat 在执行 jsp 过滤器之前显示欢迎页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆