To solve your problem, you can either send a “Redirect” back to the client or use a RequestDispatcher and forward your request to another page:
Redirect:
A redirection is made using the HttpServletResponse object:
if(condition) {
response.sendRedirect("page1.html");
} else {
response.sendRedirect("page2.html");
}
RequestDispatcher:
A request dispatcher can be obtained through the ServletContext. It can be used to include another page or to forward to it.
if(condition) {
this.getServletContext()
.getRequestDispatcher("page1.html").forward();
} else {
this.getServletContext()
.getRequestDispatcher("page2.html").forward();
}
Both solutions require, that the pages are available in you document root. If they are located somewhere else on your filesystem, you have to open the file manually and copy their content to the output writer.
If your application server is set up in combination with a normal web server like Apache, you should use solution (1), because the the web server usually serves static files much faster than the application server