Filtering static content Jersey

自作多情 提交于 2019-12-12 13:19:15

问题


I'm trying to serve static content (a HTML form that calls a Jersey REST resource) from the same webapp as the servlet that handles the requests to the resource. As I understand I can filter requests to static content away from the Jersey servlet. My web.xml is as follows, but at the moment I am unable to access the static content nor the resource...both were working separately.

<filter>
    <filter-name>my-filter</filter-name>
    <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
        <param-value>/*.html</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>my-filter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
    <servlet-name>my-service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.mydomain.ws.myservice</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>my-service</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

回答1:


FWIW your original problem was probably because the param-value for the WebContentRegex was not a regular expression. Ok techincally it was, but it is not matching what you probably want. You should try something like /.*.html instead.




回答2:


I setup my services such that the rest service are under their own subpath separate from the static content:

<servlet-mapping>
    <servlet-name>ServletAdaptor</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>


来源:https://stackoverflow.com/questions/3982005/filtering-static-content-jersey

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