java2db

Use of ServletContext object in servlet with example



For each Web-application , the container creates one ServletContext object at the time of web application deployment or at server start-up (if the web application already deployed).

 

Use of ServletContext object in servlet with example It is the object of servlet container class that implements javax.servlet.ServletContext interface.

Use of ServletContext object in servlet with example All servlets/JSPs  from a web application can access the ServletContext object.So it is called the global memory of the web application.

Use of ServletContext object in servlet with example Using ServletContext object in servlet, we can read the values of <context parameter> from web.xml , possible to do filter operations and we can gather server information.

Use of ServletContext object in servlet with example The servlet container destroys ServletContext object when  the web application is stopped/reloaded/un-deployed.

 

 

get the form data in servlet

 

 

Use of ServletContext object in servlet with example Code to get ServletContext object in servlet :

ServletContext context = getServletContext();
OR
ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();

 

Use of ServletContext object in servlet with example Complete example to get ServletContext object in servlet :

In the below example , we are reading the <context-param> values from the web.xml file.

Use of ServletContext object in servlet with example index.jsp

Use of ServletContext object in servlet with example ContextParamExeServlet .java

Use of ServletContext object in servlet with example web.xml

Use of ServletContext object in servlet with example Execution Result :
get the form data in servlet

On button click, we will get the below result.

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]



^ <