2 Minutes To Code (β Version)

Java Servlets - 2 minute tutorial

Second Servlet (doPost()) - How to handle POST http request

We began with writing a servlet to handle HTTP GET requests. Now let's write one to handle HTTP POST request.

The only difference with the earlier servlet is that this time we will override the doPost(..)
package com.techfundaes.servletsBag;

import java.io.IOException;
import java.io.PrintWriter;

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

public class SecondServlet extends HttpServlet
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
		PrintWriter pWriter = resp.getWriter();
		pWriter.println("Hi Friends");