protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String method = request.getMethod(); if (method.equalsIgnoreCase("GET")) { //Code for GET request handling } else if (method.equalsIgnoreCase("POST")) { //Code for POST request handling } }
if (request.getMethod().equals("GET")) { //Code for handling GET request } else { //Code for handling other HTTP methods (POST, PUT, DELETE, etc) }In this example, we are using the getMethod() method to determine if the request type is GET, and perform specific actions accordingly. The package library for javax.servlet.http is part of the Java Servlet API. It provides a set of interfaces and classes for the development of server-side web applications in Java.