Friday, February 10, 2012

java - Request Parameters

import java.io.*;
import java.servlet.*;
import javax.servlet.*;

public class RequestParamExample extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println("GET Request. No Form Data Posted");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse res)
    throws IOException, ServletException
    {
        Enumeration e = request.getParamterNames();
        while (e.hasMoreElements()) {
            String name = (String)e.nextElement();
            String value = request.getParamter(name);
            out.println(name + " = " + value);
        }
    }
}

No comments: