Java 过滤器-忽略不包括欢迎文件的其他请求
我编写了一个过滤器,在用户登录页到达欢迎文件之前决定它。欢迎文件的编写方式是,它接受过滤器的输入,并将用户导航到特定页面 我的欢迎文件标签是Java 过滤器-忽略不包括欢迎文件的其他请求,java,jsp,filter,web.xml,Java,Jsp,Filter,Web.xml,我编写了一个过滤器,在用户登录页到达欢迎文件之前决定它。欢迎文件的编写方式是,它接受过滤器的输入,并将用户导航到特定页面 我的欢迎文件标签是 <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> index.jsp 我的过滤器配置是 <filter> <filter-name>LandingPageF
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
index.jsp
我的过滤器配置是
<filter>
<filter-name>LandingPageFilter</filter-name>
<filter-class>com.mypack.test.filters.LandingPageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LandingPageFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
着陆页面过滤器
com.mypack.test.filters.LandingPageFilter
着陆页面过滤器
/*
当每个请求都通过这个过滤器时,上面的格式工作得很好,这是我想要避免的。当我点击http://localhost:8000/landing
即使我访问http://localhost:8000/landing/edit
它实际上应该绕过过滤器执行相关的servlet
我也尝试过这个/*/index.jsp
,但没有用。为什么我要使用它,因为上下文可能不同,但应用程序是相同的。使用
/index.jsp
而不是
/*/index.jsp
所以你的过滤器映射部分会变成这样
<filter-mapping>
<filter-name>LandingPageFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
</filter-mapping>
着陆页面过滤器
/index.jsp
无论上下文如何,这都有效,因为/
表示上下文路径之后的路径
例如,如果您在服务器中有两个相同应用程序部署的上下文路径,例如a和b,并且您正在使用URL访问它们
http://localhost:8000/a/
及
http://localhost:8000/b/
然后,url模式中的/
表示上下文根a
和b
之后的/
。因此,您的过滤器将仅对index.jsp执行