从另一个jsp调用一个jsp

时间:2013-11-13 02:49:51

标签: java jsp servlets

我有两台运行tomcat的机器在lan。

我可以在一台机器上从jsp调用另一台机器中的另一个jsp页面吗

我尝试过如下:

<%
  RequestDispatcher rd=application.getRequestDispatcher("http://10.44.111.149:8080/stud/sample.jsp");
  RequestDispatcher rd=application.getRequestDispatcher("/index.jsp");
  rd.include(request,response);
%>

但它给了我以下错误:

java.lang.IllegalArgumentException: Path http://10.44.111.149:8080/stud/sample.jsp does not start with a "/" character

有没有办法做到这一点。

2 个答案:

答案 0 :(得分:0)

您可以将客户端重定向到Internet上的任何URL(但不能使用getRequestDispatcher),但处理该重定向的JSP将不具有由第一个生成的任何servlet /请求/会话上下文机器(除非您使用跨服务器会话群集Web服务器)。

答案 1 :(得分:0)

RequestDispatcher不适合此类用途。相反,您可以将server.sendRedirect(...)从服务器用于远程服务器,如下所示

response.sendRedirect(remoteServerUrl);