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