我们使用 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 之前添加了吗?谢谢。