java2db

Use of ServletConfig object in servlet with an example



For each servlet class , the servlet container creates one ServletConfig  object at the time of servlet class instantiation.

 

Use of ServletConfig object in servlet with an example  Servlet container supplied java class that implements javax.servlet.ServletConfig interface and creates the ServletConfig  object.

Use of ServletConfig object in servlet with an example  By using ServletConfig  object in servlet, we can get (<init-param>) data from web.xml  and current servlet name.

Use of ServletConfig object in servlet with an example  ServletConfig object will destroy along with the servlet object (container destroys the servlet object).

 

 

Use of ServletConfig object in servlet with an example

 

 

Use of ServletConfig object in servlet with an example Code to get ServletConfig object in servlet :

ServletConfig config = getServletConfig();

 

Use of ServletConfig object in servlet with an exampleMethods that are there in ServletConfig  interface :

 Returns Type  Method Name
java.lang.String getInitParameter(java.lang.String name)
java.util.Enumeration getInitParameterNames()
ServletContext getServletContext()
java.lang.String getServletName()

 

Example to get ServletConfig object in servlet :

In the below example , we are reading <init-param> values in our servlet using ServletConfig object.
Use of ServletConfig object in servlet with an example index.jsp

 InitParamExeServlet.java

 web.xml

Execution Result :
get the form data in servlet
get the form data in servlet




Related Posts :
Kill or invalidate session using session id ( concurrent login )
Servlet Filter ( Request and Response filters in servlets ) example
URL rewriting in servlets ( Servlet session tracking )
Servlet Cookies ( Servlets session tracking with cookie )
Hidden form field in servlets ( Servlet session tracking )
Request attributes in servlet with an example ( Attribute scope )
Session attributes in servlet with example (Attribute scope)
ServletConext Attributes in servlet ( Attribute scope )
   [will not be published]



^ <