开发者

Serving files from war file

I am using a java servlet container, which serves files from the webapp directory. Say for instance I have Foo.html. host:80/Foo.html will serve this file. How do I serve the Foo.html for host:80/XXX/YYY, where XXX and YYY may be a number of things? I don't mean a redirect开发者_如何学Python though.

Not sure how important it is. I am using Jetty and Guice filters.


Map a servlet on the desired URL pattern which uses RequestDispatcher#forward() to forward to the target resource.

// ...
request.getRequestDispatcher("Foo.html").forward(request, response);

This does not reflect any change in the browser address bar like as a redirect does -if that's your actual concern after all. A redirect basically tells the browser to send a brand new HTTP request on the given location. A forward basically tells the servletcontainer to load the given resource in the response.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜