0

我们使用 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 会转发到 localhost/ourApp/ get/1234 /ExternalServlet。重定向有效。

知道为什么前锋在 Guice servlet 之前添加了吗?谢谢。

4

1 回答 1

0

我不确定造成这种情况的确切原因,但您应该能够使用 HttpServletRequestWrapper 解决它。您可能可以覆盖 getServletPath() 或 getContextPath() 返回的内容以获得您想要的效果。

另一种选择是尝试远程调试您的登台服务器并进入调度程序代码以查看它到底哪里出错了。

于 2012-02-21T16:23:31.463 回答