我在web.xml中的哪个位置放置了过滤器设置,以在Tomcat中为JSPpage启用CORS

时间:2019-06-03 07:33:53

标签: tomcat servlets cors servletcontextlistener

我们有一个网络应用,其中包含以下web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app ...>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (default). See JSF Specification section 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <welcome-file-list>
    <welcome-file>index.jsf</welcome-file>
    <welcome-file>welcome.jsf</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <listener>
    <listener-class>net.halloleo.utils.ContextListener</listener-class>
  </listener>
</web-app>

我试图通过在Web应用程序的结束标记之前web.xml的末尾添加CORS过滤器来向此Web应用程序添加CORS,

.
.
.
  <listener>
    <listener-class>net.halloleo.utils.ContextListener</listener-class>
  </listener>
  <filter>
    <filter-name>CorsFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>CorsFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>  
</web-app>

,但未为http://my.domain/data.jsp?step=3&shape=5之类的JSP页面启用CORS。我什至通过

cors.exposed.headers添加了默认值
    <init-param>
      <param-name>cors.exposed.headers</param-name>
      <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
    </init-param>

但这也不是更好。 -我在web.xml中的何处放置CORS过滤器设置,以便为JSP页面提供CORS?

0 个答案:

没有答案