When you open new tab or window you need to set the URL (with your get params).
Now you have one option (use ajax):
- create a new page or view.
- open the new page with a simple
<a target="_blank" href="url">
.
- Use a javascript function to make a async request (ajax) to the servlet.
- Populate the view with results.
Having a servlet like this:
@WebServlet("/SampleServlet")
public class SampleServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String parameter1 = request.getParameter("param1");
String parameter2 = request.getParameter("param2");
//Process request, build response
//You can return your prefered data type (html, xml...)
String jsonResponse = new Gson().toJson(new MyResponseObject(parameter1, parameter2));
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(jsonResponse);
}
}
And the "new view" (include JQuery lib):
<html>
<head>
...
<script>
$(document).ready(function (){
$.ajax({
url: '/SampleServlet',
type: "post",
data: {
param1: "param1Value",
param2: "param2Value",
},
dataType: 'json', //or html, xml...
success: function(data) {
//populate page body with servlet response (json, html, etc)
}
});
});
</script>
</head>
<body>
<!-- page content here -->
</body>
</html>