Guice 3.0 request.getRequestDispatcher(..).forward 预先添加 guice servlet 路径
我们使用 JBoss 5.1 和 Guice 3.0,需要使用以下技术从 Guice servlet 转发到外部 Servlet:
@Inject HttpServletRequest request;
@Inject HttpServletResponse response;
@GET
@Produces("application/octet-stream")
@Path("/get/1234")
public void fwd() throws ServletException, IOException {
String newURL = "/ExternalServlet?action=1234";
RequestDispatcher dispatcher = request.getRequestDispatcher(newURL);
dispatcher.forward(request, response);
}
在我们的几个开发服务器上,此转发到正确的 url(例如 localhost/ourApp/ExternalServlet),但在我们的生产阶段服务器它在 /get/1234 前面,所以 url 转发到本地主机/ourApp/get/1234/ExternalServlet。重定向有效。
知道为什么转发要在 Guice servlet 前面添加吗?谢谢。
We are using JBoss 5.1 with Guice 3.0 and need to forward from our Guice servlet to an external Servlet using the following technique:
@Inject HttpServletRequest request;
@Inject HttpServletResponse response;
@GET
@Produces("application/octet-stream")
@Path("/get/1234")
public void fwd() throws ServletException, IOException {
String newURL = "/ExternalServlet?action=1234";
RequestDispatcher dispatcher = request.getRequestDispatcher(newURL);
dispatcher.forward(request, response);
}
On several of our dev servers this forwards to the corrrect url (e.g. localhost/ourApp/ExternalServlet) but on our production staging server it is prepending /get/1234 so the url is forwarding to localhost/ourApp/get/1234/ExternalServlet. A redirect works.
Any idea why the forward is prepending the Guice servlet? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定其确切原因,但您应该能够使用 HttpServletRequestWrapper 来解决它。您可以覆盖 getServletPath() 或 getContextPath() 返回的内容以获得所需的效果。
另一种选择是尝试远程调试临时服务器并进入调度程序代码以准确查看哪里出了问题。
I'm not sure of the exact cause of this, but you should be able to work around it using an HttpServletRequestWrapper. You can probably override what the getServletPath() or getContextPath() are returning to get your desired effect.
Another option is to try remote debugging your staging server and walking into the dispatcher code to see exactly where it is going wrong.