请求.getRequestDispatcher()。转发(请求,响应)在新页面中

时间:2013-11-16 13:38:19

标签: java servlets requestdispatcher

像标题一样,我想知道在浏览器的新TAB中打开jsp页面是否可能(如果可能的话,也是如此);

现在我正在使用此功能,但页面将显示在浏览器的同一选项卡中。

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>

3 个答案:

答案 0 :(得分:2)

无法在服务器端控制。您需要在客户端控制它。例如,您可以在target="_blank"上使用<form>

<form name="input" action="${toServlet}" method="POST" target="_blank">
...
</form>

答案 1 :(得分:1)

在浏览器的新选项卡中打开URL是必须在客户端完成的(使用链接的目标属性或JavaScript)。服务器对标签甚至浏览器一无所知。它只接收请求并发回响应。如果这些请求来自一个标签,10个标签,一个机器人,一个wget命令或其他什么,他就不会在意。

所以不,你不能从服务器端运行的代码中打开一个新的浏览器选项卡。

答案 2 :(得分:0)

是的,你应该实现一个servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.getRequestDispatcher("page.jsp").forward(request, response);
}
相关问题