public
String getMethod()
Returns
the name of the HTTP method with which this request was made, for
example, GET, POST, or PUT.
import java.io.*; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*; @WebServlet(urlPatterns = {"/GetRequestedMethod"}) public class GetRequestedMethod extends HttpServlet { @Override public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{ try(PrintWriter out = res.getWriter()){ String method; method = req.getMethod(); out.println("<html><head><title>Server Details</title>"); out.println("<body><h1>"); out.println("Requested Method type: " + method); out.println("</h1></body></html>"); } } @Override public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{ doPost(req, res); } }
No comments:
Post a Comment