[New post] Servlets

9 views
Skip to first unread message

Encapsulate {Ideas}

unread,
Sep 17, 2015, 3:50:24 AM9/17/15
to post.encap...@gmail.com
prime posted: "Servlet is an interface present in javax.servlet package, which has 5 methods declared. To implement the servlet in our java class we need to implement all the following five methods: 1)public void init(ServletConfig config) : initializes the servlet,in "
Respond to this post by replying above this line

New post on Encapsulate {Ideas}

Servlets

by prime

Servlet is an interface present in javax.servlet package, which has 5 methods declared.
To implement the servlet in our java class we need to implement all the following five methods:

1)public void init(ServletConfig config) : initializes the servlet,in life cycle of servlet this method
is invoked by webcontainer only once.
2)public void service(ServletRequest request,ServletResponse response): it is invoked each time
when the webcontainer requests.
3)public void destroy() : it is invoked once when the servlet is to be destroyed.
4)public ServletConfig getServletConfig(): returns the object of ServletConfig.
5)public String getServletInfo() : returns information about servlet like version,copyright etc.

 

Basic Servlet

Basic Servlet

 

out of the above five methods we generally most of time use service method only.
and rest of the method is usually common for all the servlets.

So to remove this work,we have GenericServlet abstract class in javax.servlet package
which implement all the other methods of servlet interface except service method.

Genric servlet

Genric servlet

 

But this also has some draw backs, as it is Generic so it supports basic features of all protocols but not specific features of any protocols like sessions , cookies etc. features of Http Protocol.
So to overcome this their is HttpServlet abstract class in package javax.servlet.http by extending this class we can all the specific features of Http Protocol.

Http Servlet

Http Servlet

 

prime | September 17, 2015 at 7:50 am | Categories: Servlet | URL: http://wp.me/s5JOdg-servlets

Comment    See all comments    Like

Unsubscribe to no longer receive posts from Encapsulate {Ideas}.
Change your email settings at Manage Subscriptions.

Trouble clicking? Copy and paste this URL into your browser:
https://encapsulateideas.wordpress.com/2015/09/17/servlets/

Thanks for flying with WordPress.com

Reply all
Reply to author
Forward
0 new messages