Search This Blog

Total Pageviews

ProgramResourceServlet Example Extending HttpServlet

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Map;

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

public class ProgramResourceServlet extends HttpServlet

   public void init() throws HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws Servlet Exception, IOException {
        handleServletRequest(req, res);

    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        handleServletRequest(req, res);

    public void handleServletRequest(HttpServletRequest req, HttpServletResponse res) throws IOException {

        PrintWriter out = res.getWriter();

        Enumeration<String> parameterNames = req.getParameterNames();

        while (parameterNames.hasMoreElements()) {

            String name = parameterNames.nextElement();

            String[] paramValues = req.getParameterValues(name);
            for (int i = 0; i < paramValues.length; i++) {
                String paramValue = paramValues[i];
                out.write("Param Value " + paramValue);

No comments:

MongoDB Tutorial MongoDB Tutorial Table of Contents Introduction to MongoDB Installation Creating a Database Creati...