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

Can we override destroy method in servlet?

495


What is http servlet in java?

556


What is servlet interface?

694


How do you invoke a Servlet? What is the difference between doPost method and doGet method?

644


What is the difference between genericservlet and httpservlet

584






What is a web application and what is it’s directory structure?

582


What is the difference between CGI and Servlet?

585


Is servlet synchronized?

599


What is java servlet session?

524


Whether we can get deadlock situation in servlets?

572


What is the procedure for initializing a servlet?

543


Why is httpservlet declared abstract?

582


Can you create a deadlock condition on a servlet?

587


How we can call a jsp from the servlet?

529


How do you deal property files in servlet?

598