I have a JSP page that contains a form from which I have to call a servlet. But even after adding servlet mapping in web.xml
and also trying webservlet annotations, the JSP page itself is not loading. I am confused as to what to do.
JSP page:
<html><h1>Active Users </h1><body><form id="userForm" action="${pageContext.request.contextPath}/users" method="post"><ul id="list" style="list-style: none;"><input type="submit" name="delete" value="Delete"/><input type="reset" name="cancel" value="Cancel"/></ul></form></body></html>
The calling servlet:
//@WebServlet(name = "users", urlPatterns = ("/users"))public class UserManagementControllerServlet extends HttpServlet{ private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UserManagementControllerServlet() { super(); } public void init() throws ServletException{ Logger.getLogger(UserManagementControllerServlet.class).info("UserManagementControllerServlet initiated");} @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try{ //to do response.sendRedirect("users.jsp"); }catch(Exception e){ } System.out.println("Reached here!!"); }}
And here is my web.xml
configuration:
<servlet><servlet-name>UserManagementControllerServlet</servlet-name><servlet-class>com.ehc.plugins.UserManagementPlugin.UserManagementControllerServlet</servlet-class><jsp-file>/jsp/users.jsp</jsp-file></servlet><servlet-mapping><servlet-name>UserManagementControllerServlet</servlet-name><url-pattern>/users</url-pattern></servlet-mapping>