2
我有一个route()
,当我去并且它正在工作时触发,但它阻止我的资源加载。例如http://localhost:8080/mobile/css/styles.css
返回404JAX-RS @Path阻止来自加载的静态资源
我在我的代码中使用了<url-pattern>/</url-pattern>
在我的web.xml和@Path("/")
。任何想法如何在动态创建index.html的同时提供静态内容?
谢谢!
编辑 - 我想避免做一个重定向,并保持我的URL清洁。如果有另一个框架可以做得更好,我愿意尝试。我没有附加到JAX-RS。
package com.project.router;
@Path("/")
@Produces({MediaType.TEXT_HTML})
public class Router {
final String FULL_WEB = "";
final String MOBILE_WEB = "C:\\workspace\\project\\web\\mobile\\index.html";
@GET
@Produces({MediaType.TEXT_HTML})
public Response route(@HeaderParam("user-agent") String userAgent, @HeaderParam("accept") String accept) throws FileNotFoundException {
UAgentInfo uAgentInfo = new UAgentInfo(userAgent,accept);
boolean tierIphone = uAgentInfo.detectTierIphone();
File file = null;
if (tierIphone) {
file = new File(MOBILE_WEB);
} else {
file = new File(FULL_WEB);
}
FileInputStream fileInputStream = new FileInputStream(file);
return Response.ok().entity(fileInputStream).build();
}
}
的web.xml
<servlet>
<servlet-name>router</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.project.router</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>router</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
所以'/ URL模式>'和'/* URL模式>'都是相同的? –
sissonb
我想要http:// localhost /为服务动态html文件,而不是http:// localhost/router。另外我想避免重定向。 – sissonb
检查此[post](http://stackoverflow.com/questions/7448316/how-to-exclude-redirect-certain-url-pattern-in-web-xml-or-guice-servlet-module)有帮助。 – basiljames