{{theTime}}

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();
        res.setContentType("text/plain");

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

        while (parameterNames.hasMoreElements()) {

            String name = parameterNames.nextElement();
            out.write(name);
            out.write("\n");

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

No comments:

Best Client Optimized Programming Language for Mobile Development?

Use Google's Dart language, which is Object-oriented, class-based and garbage-collected language with C-Style.  Dart can compile to eith...