簡體   English   中英

從另一個jsp調用一個jsp

[英]Calling one jsp from another jsp

我有2台運行Tomcat的機器在局域網中。

我可以從一台機器上的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

有什么辦法可以做到這一點。

您可以將客戶端重定向到Internet上的任何URL(盡管不能使用getRequestDispatcher進行重定向),但是處理該重定向的JSP將沒有第一台機器生成的任何servlet / request / session上下文(除非您正在集群)具有跨服務器會話的Web服務器)。

RequestDispatcher不適用於此類用途。 相反,您可以使用從服務器到遠程服務器的response.sendRedirect(...),如下所示

response.sendRedirect(remoteServerUrl);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM