简体   繁体   English

从另一个jsp调用一个jsp

[英]Calling one jsp from another jsp

I have 2 machines running tomcat which are in lan. 我有2台运行Tomcat的机器在局域网中。

Can I make a call from jsp in one machine to another jsp page in another machine 我可以从一台机器上的jsp呼叫另一台机器上的另一jsp页面吗

I have tried it as follows: 我已经尝试过如下:

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

But it gave me the following error: 但这给了我以下错误:

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

Is there any way to do this. 有什么办法可以做到这一点。

您可以将客户端重定向到Internet上的任何URL(尽管不能使用getRequestDispatcher进行重定向),但是处理该重定向的JSP将没有第一台机器生成的任何servlet / request / session上下文(除非您正在集群)具有跨服务器会话的Web服务器)。

RequestDispatcher is not intended for such an use. RequestDispatcher不适用于此类用途。 Instead you can use response.sendRedirect(...) from your server to the remote server as below 相反,您可以使用从服务器到远程服务器的response.sendRedirect(...),如下所示

response.sendRedirect(remoteServerUrl);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM