Spring MVC: Open link in new browser window in handler method

Spring MVC: Open link in new browser window in handler method

I solved this using JavaScript and AJAX – as @Patrick suggest. Maybe it will be helpful for someone.

<a href=# onclick=openLink(${link.id},${link.address});>Open</a>

openLink function:

function openLink(id, url) {
    jQuery.get(open.html?id=+id, function(data) { 
      if(data == OK) {
        window.open(url);
      } 
    }, text);
}

Handler method:

@ResponseBody
@RequestMapping(value = /open.html)
public String open(@RequestParam(value=id) Integer id) {
    Link link = linkDAO.get(id);
    linkDAO.click(id);
    return OK;
}

Spring MVC: Open link in new browser window in handler method

Leave a Reply

Your email address will not be published. Required fields are marked *