This post is may be old. But here is my answer.
You can create a link like this in jsp page.
<a href="${pageContext.request.contextPath}/new">Add New Book</a>
<a href="${pageContext.request.contextPath}/list">List All Books</a>
And call your controller like this.
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String action = request.getServletContext().getContextPath()+request.getServletPath();
try {
switch (action) {
case "/new":
showNewForm(request, response);
break;
case "/insert":
insertBook(request, response);
break;
case "/delete":
deleteBook(request, response);
break;
case "/edit":
showEditForm(request, response);
break;
case "/update":
updateBook(request, response);
break;
default:
listBook(request, response);
break;
}
} catch (SQLException ex) {
throw new ServletException(ex);
}
}
This is for a servlet that keeps as the startup page.
You can update the href
attribute according to the url pattern
of the servlet.