Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Servlets Code Examples

Hello servlet

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
Hello servlet //J2SE Libraries; import java.io.IOException; import java.io.PrintWriter; //J2EE Libraries; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * *A very basic servlet which prints Hello world! *For addtional documentation refer-> http://java.sun.com/servlets *For addtional documentation refer-> http://java.sun.com/jsp */ public final class HelloServlet extends HttpServlet { public void init(ServletConfig config) throws ServletException { super.init(config); }; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); }; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out= response.getWriter(); out.println("<HTML><BODY>"); out.println("Hello world!"); out.println("</BODY></HTML>"); } //optional method; public void destroy() { System.gc(); } }