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 can we refresh automatically when new data is entered into the database?

684


What are sessions in servlets?

672


How do I use cookies to store session state on the client?

613


What do you mean by cgi in servlet?

714


What are the difference between session and cookies in servlet? Explain

645






What are all the protocols supported by httpservlet?

731


What is a deployment descriptor?

692


What are the disadvantages of storing session state in cookies?

736


Can you call a jsp from the servlet?

636


When using servlets to build the HTML, you build a DOCTYPE line, why do you do that?

661


Explain web container.

675


Whats the advantages using servlets over using CGI?

664


Differentiate between the print writer and servlet output stream?

631


Is that servlet is pure java object or not?

716


What is the element?

670