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
What are the life cycle methods of the servlet?
Whether we can get deadlock situation in servlets?
Why do we need servlet filter?
What are the life-cycle methods for a servlet?
How to make sure a servlet is loaded at the application startup?
How do you create a cookie using servlet?
What are the different methods involved in the process of session management in servlets?
What are the servlet events?
What’s the difference between sendredirect and forward methods
Describe in brief RequestDespatcher?
What is the need of session tracking in web application?
How do I know if java is running on linux?
why we should override only no-agrs init() method.
Explain the features are in servlet 3?
What is the directory structure of a war file?