过滤静态内容泽西岛 [英] Filtering static content Jersey

查看:111
本文介绍了过滤静态内容泽西岛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从与处理资源请求的servlet相同的Web应用程序中提供静态内容(一种称为Jersey REST资源的HTML表单).据我了解,我可以过滤对来自Jersey Servlet的静态内容的请求.我的web.xml如下,但是此刻我无法访问静态内容,也无法访问资源...两者都在单独工作.

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>

推荐答案

FWIW最初的问题可能是因为WebContentRegex的param-value不是正则表达式.从技术上讲可以,但是它与您可能想要的不匹配.您应该改用/.*.html之类的方法.

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.

这篇关于过滤静态内容泽西岛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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