Is there any differance b/w getting servlet context from
servlet config and session? if yes then what is that?

Answer Posted / frank tamaguchi

The ServletContext returned from ServletConfig and from
HttpSession are the same instance, the one instance that
exists while the web application is running. You can confirm
it with a debugger.

The main differences though are that you get a reference to
ServletConfig when in a Servlet and you get a reference to
an HttpSession from an HttpServletRequest.

You can get a reference to a ServletContext from a
FilterConfig when in a Filter.

If you are not in a Servlet and don't want to create an
HttpSession through a call to
HttpServletRequest.getSession() to be able to get a
reference to a ServletContext then create a Filter which
puts a reference to the ServletContext in a request attribute.

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How servlet is created?

801


What are the types of an http request?

844


What are the exceptions thrown by servlets? Why?

861


What are the steps involved in placing a servlet within a package?

852


What is servletconfig?

778


What is the use of java servlet api?

809


Why filter is used in servlet?

756


What is the difference between Servlet Request and Servlet Context when calling a Request Dispatcher?

865


What do you mean by the servlet chaining?

812


List the Different types of servlet?

809


What is lazy loading and what is Generic Servlet Class?

843


Which httpsession object is used to view and manipulate information about a session?

964


What is the servlet?

850


List some life cycle methods of a servlet.

805


Which java framework is most popular?

803