1

like the title say I would like to know if it's possible (and if it's possible, also how) to open a jsp page In a new TAB of the browser;

Now I'm using this istruction but the page will appear in the same tab of the browser.

request.getRequestDispatcher("page.jsp").forward(request, response);

the call to the servlet, in the client side is this:

<img id="imgModAbb" src="imm/historyAbb.png"
                        title="Vedi storico modifiche" 
                        onclick="window.location.href='/Spinning/InfoStoricoAbbonamento?id=<%=a.getIdAbbonamento()%>'">

SOLUTION

I modified the calling in the client-side:

<a href="ServletAddress" target="_blank">
 <img id="imgModAbb" src="imm/historyAbb.png" title="Vedi storico modifiche">
</a>
Martina
  • 1,852
  • 8
  • 41
  • 78

3 Answers3

2

That cannot be controlled in the server side. You need to control that in the client side. For example, you can use target="_blank" on <form>:

<form name="input" action="${toServlet}" method="POST" target="_blank">
...
</form>
Debojit Saikia
  • 10,532
  • 3
  • 35
  • 46
1

Opening a URL in a new tab of the browser is something that must be done at client side (using target attributes of links, or JavaScript). The server doesn't know anything about tabs or even browsers. It just receives requests and sends back responses. And he couldn't care less if these requests come from one tab, 10 tabs, a bot, a wget command or whatever.

So no, you can't open a new browser tab from code running at server-side.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
0

Yes it's possible, you should implement a servlet

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