Get Request Parameters in a Servlet : Do Get Do Post « Servlets « Java

Get Request Parameters in a Servlet


import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Main extends HttpServlet {
  protected void service(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    PrintWriter out = response.getWriter();

    Enumeration en = request.getParameterNames();

    while (en.hasMoreElements()) {
      String paramName = (String) en.nextElement();
      out.println(paramName + " = " + request.getParameter(paramName) + "<br/>");


Related examples in the same category

1.Simple servlet: Copyright
2.Print various CGI variables that have been requested by the servlet
3.Print all header information available from the client
4.Request header viewer
5.Request binder
6.Request display
7.Servlet Request Listener
8.Client auto refresh