DoGet in servlet

This is what I am trying to implement. I wrote a doGet method, how do I now map the doPost method?

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String forward=""; String act = request.getParameter("act"); if (act != null && !act.equalsIgnoreCase("null") && act.equalsIgnoreCase("login")) { forward= "/Login.jsp"; } else if (act!= null && !act.equalsIgnoreCase("null") && act.equalsIgnoreCase("register")) { forward = LIST_USER; request.setAttribute("users", dao.getAllUsers()); } else { forward = "/Login.jsp"; } RequestDispatcher view = request.getRequestDispatcher(forward); view.forward(request, response); } 
0
source share
3 answers

If you want to handle POST in the same way as GET, you can do

 protected void doPost((HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } 
0
source

if you want to handle POST and GET in the same way, you can add a third method

 doSomething(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 

and name it as from

doGet and make a message

eg

 doSomething(request,response); 
0
source

This is the default code generated by the Netbeans IDE.

Store your code in a generic method and map it to your calling method.

 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } 
0
source

All Articles