postheadericon hello world servlet example

Step 1 :  Create .java File using text editor


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class ServletDemo extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML><HEAD><TITLE>WTAD</TITLE></HEAD> <body>");
String str="<h1>welcome to </h1>";
str=str+"<br>www.bipinrupadiya.blogspot.com";
out.println(str);
        out.println("</body> </html>");
}
}




Step 2 :  Go to Command prompt and compile it




Step 3 :  Create Web Application structure and upload your .class / servlet file  on  server




Step 4 :  Create web.xml 



Step 4 :  Explore your servlet

           http://hostname/appName/my-address           http://localhost:8081/bipin/wtad/bsr.co.in

n  Protocol
n  Custom URL for servlet
n  Web Application name
n  Host / domain name

Step 4 :  output of servlet on Firefox

 




1 comments:

Unknown said...

Thank you sir.....

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.