The Servlet Basic Structure
Kushal Paudyal January 20th, 2010
/**
* @author Kushal Paudyal
* www.sanjaal.com/java
* Created on 19th July 2008
*/
package com.kushal.servlets;
/*
* This is a basic servlet class that shows how
* servlet can be structured.
*/
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyFirstServlet extends HttpServlet {
/**
* This is GET method. Request has parameters,
* and we write back using response.
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.write("Hello, this is my first servlet");
}
/**
* This is another kind of request with POST
* kind of submission. We can simply reroute
* the request to doGetmethod as below.
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
/**
* In order to be able to run this servlet, you have
* to setup a proper application server and deploy
* the servlet. Discussing those steps is out of
* scope in this post.
*/
Sanjaal.com is owned and maintained by Sanjaal Corps, Nepal. The company offers Webhosting and Domain Registration Services, IT Solutions and Business Analysis. Sanjaal.com website features H1B Visa Information, Entertainment Portal, Link Directory Service, Free Articles, Free Open Source Tutorials on Java and J2EE Platform, Digital Photography, High Resolution Picture Gallery and Free Reliable Image Hosting Services. Future plan includes Open Source Software Development Portal, Technical Solutions and Customizable Movie and Music Arena. We would be introducing data backup, data recovery, data hosting and voip solutions. Stay free from phishing – our website does not ask for your credit card and banking information. Happy Surfing!
Originally posted 2008-07-19 23:24:23.
