Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a JSP Context?

I was wondering what exactly this java object is and what its main purpose is. I have looked java documentation, but that confuses me more :(.

Does it have any relation scopes such as session, request, application?

like image 405
Apoorv Kansal Avatar asked Dec 11 '12 10:12

Apoorv Kansal


People also ask

What is servlet context in Java?

public interface ServletContext. Defines a set of methods that a servlet uses to communicate with its servlet container, for example, to get the MIME type of a file, dispatch requests, or write to a log file. There is one context per "web application" per Java Virtual Machine.

What is pageContext object in JSP?

The pageContext object is used to represent the entire JSP page. This object is intended as a means to access information about the page while avoiding most of the implementation details. This object stores references to the request and response objects for each request.

What is scope in JSP?

scope="session" : The object is accessible from any JSP page that is sharing the same HTTP session as the JSP page that created the object. A session-scope object is stored in the implicit session object.


1 Answers

The JspContext

enter image description here

enter image description here

enter image description here

The JspContext is confusing, because it doesn't seem to do anything that the ServletContext can't do. You're right, it doesn't. You can live without the JspContext. The implicit variables are there at your disposal.

The primary benefit lies in the fact that the JSP technology is not necessarily bound to Java. Yes. You heard that correctly, JSPs are positioned to be cross-platform compatible.

Quoting the API:

JspContext serves as the base class for the PageContext class and abstracts all information that is not specific to servlets. This allows for Simple Tag Extensions to be used outside of the context of a request/response Servlet.

This abstraction allows a JSP to gather information about its environment (request, session and application scope) in a platform-neutral manner.

like image 167
Jops Avatar answered Oct 12 '22 23:10

Jops