Return to Snippet

Revision: 65029
at October 17, 2013 08:12 by rnavanee


Initial Code
package com.nav.sample.servlet3;

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

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloServlet3
 */
@WebServlet("/Hello")
public class HelloServlet3 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
	}
	
    /**
     * Default constructor. 
     */
    public HelloServlet3() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter pWriter = response.getWriter();
		pWriter.write("Hello "+request.getParameter("user"));
		pWriter.flush();
		pWriter.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}

Initial URL

                                

Initial Description
Description: A sample HelloServlet for Servlet3.0 specification. No web.xml file is required in this case.
Jars: servlet-api.jar (spec version: 3.0, Implementation-Vendor: Apache Software Foundation)
URL: http://localhost:8080/TestServlet3/Hello?user=nav
Output: "Hello nav"

Initial Title
HelloServlet for Servlet3.0

Initial Tags

                                

Initial Language
Java