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

What is the difference between a generic servlet and http servlet?

724


How to handle exceptions thrown by application with another servlet?

815


How do you run a servlet?

778


What are the uses of servlet and what is servlet chaining?

798


List out difference between a JavaBean from a Servlet?

747


What are the phases of the servlet life cycle?

808


What is servlet interface?

939


What is the difference between servlet and jsp?

809


How are filters?

803


Tell the new features added in servletrequest interface i.e. Servlet 2.4

827


How can you push data from an Applet to a Servlet?

839


List some life cycle methods of a servlet.

790


Explain the jar and war files in servlet?

809


Is servlet a framework?

752


How do I support both get and post from the same servlet?

945