[英]Will request.getRequestDispatcher().forward creates new thread?
[英]request.getRequestDispatcher().forward(request, response) in a new page
喜歡標題說我想知道是否有可能(如果可能,也是如此)打開一個jsp頁面在瀏覽器的新TAB中;
現在我正在使用此istruction,但頁面將出現在瀏覽器的同一選項卡中。
request.getRequestDispatcher("page.jsp").forward(request, response);
在客戶端調用servlet是這樣的:
<img id="imgModAbb" src="imm/historyAbb.png"
title="Vedi storico modifiche"
onclick="window.location.href='/Spinning/InfoStoricoAbbonamento?id=<%=a.getIdAbbonamento()%>'">
我修改了客戶端的調用:
<a href="ServletAddress" target="_blank">
<img id="imgModAbb" src="imm/historyAbb.png" title="Vedi storico modifiche">
</a>
這無法在服務器端進行控制。 您需要在客戶端控制它。 例如,您可以在<form>
上使用target="_blank"
:
<form name="input" action="${toServlet}" method="POST" target="_blank">
...
</form>
在瀏覽器的新選項卡中打開URL是必須在客戶端完成的(使用鏈接的目標屬性或JavaScript)。 服務器對標簽甚至瀏覽器一無所知。 它只接收請求並發回響應。 如果這些請求來自一個選項卡,10個選項卡,一個機器人,一個wget命令或其他什么,他也不會在意。
所以不,你不能從服務器端運行的代碼打開一個新的瀏覽器選項卡。
是的,你應該實現一個servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("page.jsp").forward(request, response);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.