[英]Unable to serve static content with Jersey2.0
I'm having trouble serving static content with jersey. 我在使用球衣投放静态内容时遇到问题。 I'm using Jersey 2.4.
我正在使用Jersey 2.4。
Here is my web.xml: 这是我的web.xml:
<?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"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
<filter>
<filter-name>jersey</filter-name>
<filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
<init-param>
<param-name>jersey.config.servlet.filter.forwardOn404</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.nile.cardealer.resources</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.server.mvc.jsp.JspMvcFeature</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.mvc.templateBasePath.jsp</param-name>
<param-value>/WEB-INF/static/jsp/</param-value>
</init-param>
<init-param>
<param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
<param-value>/WEB-INF/static/(css|js).*</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>jersey</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
And my file structure under WEB-INF looks like: 我在WEB-INF下的文件结构如下所示:
WEB-INF WEB-INF
-static -静态的
--css --css
---main.css ---的main.css
--js --js
I'm unable to request main.css even though I have the jersey.config.servlet.filter.staticContentRegex propery set. 即使设置了Jersey.config.servlet.filter.staticContentRegex属性,我也无法请求main.css。 I've tried http://localhost:8084/CarDealer/static/css/main.css , http://localhost:8084/CarDealer/main.css and neither are able to retrieve the static resource.
我已经尝试过http:// localhost:8084 / CarDealer / static / css / main.css , http:// localhost:8084 / CarDealer / main.css ,但都无法检索静态资源。 Other solutions on this site for similar problems haven't worked.
该站点上针对类似问题的其他解决方案均无效。
Generally WEB-INF is a place for placing jars and deployment descriptor stub(web.xml). 通常,WEB-INF是放置jar和部署描述符stub(web.xml)的地方。 Keep the contents outside of WEB-INF (but inside web content) folder and change path name accordingly in web.xml file.
将内容保留在WEB-INF之外(但在Web内容之内),并在web.xml文件中相应地更改路径名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.