• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet Context Object?  RSS feed

 
Ramesh Kale
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for this question?
I am asking very basic question... But I am really not understand what is the exact position of this object in Servlet Application.

very confuse bcoz of this line ... plz explain this line
"A servlet lives and dies within the bounds of the server process." with example.

Thanks in Advance
 
Somnath Jamdar
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Congratulation on your SCJP success!!!


ServletContext has application wide scope whereas
ServletConfig has Servlet Scope

Parameters defined in the ServletContext are visible to all
servlets for a web application

whereas parameters defined with ServletConfig are visible to the servlet where it has been defined

ServletContext has a lifetime as that of Container.

Please have a look at this lesson
http://members.chello.nl/karin2/scwcd/section3.html

Also in web.xml we define context parameters in application scope


<web-app> <--------- Container Scope

<context-param>
<param-name>appdb-url</param-name>
<param-value>jdbc dbc:MySQLODBC</param-value>
</context-param>

<servlet> <--------- Servlet Scope
<servlet-name>AccountServlet</servlet-name>
<servlet-class>AccountDetails</servlet-class>
<init-param>
<param-name>driverclassname</param-name>
<param-value>sun.jdbc.odbc.JdbcOdbcDriver</param-value>
</init-param>
</servlet>
</web-app>


BTW, When r u giving SCWCD??
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ServletConext object has application scope, that is, it (or more importantly, its parameters) is accessible by any servlet (or jsp) in the application. There is only one object per application, and it is created when the application is deployed.
 
vara prasad
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from those described about ServletContext object is used to communicate with the container. A Servlet developer can use the log method that is provided as part of servletContext for logging. (logging means storing the information in a log file). Every web container writes the log message to a logfile. when we use ServletContext.log() (SC.log()) the information will be returned to logfiles.
 
gudla Dathathreya Reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prasad, Paul, Jamdar,
You are still confusing Ramesh, He did'nt asked about ServletContext or ServletConfig what does blah, blah.... Might this answer will suit his question.

"The server processes(Servlet Container) of the J2EE Engine(Weblogic, WebSphere, Tomcat etc) actually execute the J2EE application(Containing Servlets). The server processes (Servlet Container) is multi-threaded, and can therefore process a large number of requests simultaneously(Handle Servlets). So the scope of the Servlet object either live or die is between the server processes .


Any comments please..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!