Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on servlet

Status
Not open for further replies.

preethib

Programmer
Jul 20, 2000
39
IN
Since A Java servlet is implemented within a Java class. What requirements are imposed on this class?
 
A Servlet is just a Java class that does one of three things:
1) Implements the javax.servlet.Servlet Interface.
2) Extends from javax.servlet.GenericServlet
3) Extends from javax.servlet.HttpServlet

Futhermore (straight from JavaDocs):
Code:
A subclass of HttpServlet must override at least one method, usually one of these:

· doGet, if the servlet supports HTTP GET requests 
· doPost, for HTTP POST requests 
· doPut, for HTTP PUT requests 
· doDelete, for HTTP DELETE requests 
· init and destroy, to manage resources that are held for the life of the servlet 
· getServletInfo, which the servlet uses to provide information about itself

That's it. You should probably know that 99.9% of all Servlets take the third option and extend from javax.servlet.HttpServlet. It is important to note that a Servlet doesn't have to serve HTTP Requests though, by extending from GenericServlet you could create a Servlet to handle FTP, SMTP, whatever.
 

Hi ,

I am new to servlets.I will be extremely greatfull if wushutuvist or somebody can guide me through. I have written a simple servlet HelloServlet.java and compiled it getting HelloServlet.class file. But to execute this what am i supposed to do at the localhost.What changes are needed in the Web.xml file for servlet mapping etc.
thanks

Da21
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top