Can jsp:include pages pass through filters

梦想与她 提交于 2020-01-06 13:09:22

问题


I have a jsp page in which includes a jsp page through jsp:include. Now the question is does the request for the included jsp pass through the filter? following is my filter mapping in web.xml

    <filter-mapping>
    <filter-name>XYZFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

But this doesnt seem to work. The filter doesn't get called for the included jsp. What am I doing wrong or is it possible at all?


回答1:


The <dispatcher> support was introduced in Servlet 2.4. So when it does not work, then it likely means that you're running your webapp on an outdated Servlet 2.3 container (Tomcat 5.0 for example) or that your web.xml is declared as per Servlet 2.3 DTD or does not have a version specific declaration at all which would force the container to fall back to least compatibility modus.

Please ensure that your web.xml is declared conform the maximum Servlet API version as supported by the target runtime. When your target runtime is for example Tomcat 6.0, which is a Servlet 2.5 container, then you should be declaring the web.xml conform Servlet 2.5:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <!-- Your config here -->
</web-app>



回答2:


This should work. <dispatcher>INCLUDE</dispatcher> in your filter mapping says that include the filter for include dispatches also.

Debug your code, somewhere else it is going wrong.



来源:https://stackoverflow.com/questions/6330651/can-jspinclude-pages-pass-through-filters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!