Latest web development tutorials

JSP implicit objects

JSP implicit objects JSP container is provided for each page of Java objects, developers can use them directly without an explicit declaration. JSP implicit objects are also known as predefined variables.

JSP supports nine implicit objects:

Objects description
request Examples of HttpServletRequest class
response Examples HttpServletResponse class
out Examples PrintWriter class is used to output the result on the page
session Examples HttpSession class
application ServletContext instance of the class, and context-sensitive application
config Examples ServletConfig class
pageContext Examples PageContext class JSP page provides access to all the objects and namespaces
page Similar to the Java class in this keyword
Exception Exception class object that represents the error occurred JSP page corresponding exception object

Object request

javax.servlet.http.HttpServletRequest request object is an instance of the class. Whenever a client requests a JSP page, JSP engine will create a new request object to represent the request.

request object provides a series of methods to get the HTTP headers, cookies, HTTP methods, and so on.


response objects

javax.servlet.http.HttpServletResponse response object is an instance of the class. When the server creates request objects simultaneously created in response to the client's response object.

response objects are also defined in the HTTP header processing module interface. Through this object, developers can add new cookies, timestamp, HTTP status code, and so on.


out objects

javax.servlet.jsp.JspWriter out object is an instance of the class, in response to written content object.

The initial JspWriter class object according to whether the page cache to different instances of operation. You can use buffered = 'false' attribute in the page directive to easily turn off caching.

JspWriter class contains most java.io.PrintWriter class method. However, JspWriter add some methods designed to handle caching and design. There is, JspWriter IOExceptions class will throw an exception, while PrintWriter does not.

The following table lists the important methods we will use the output of boolean, char, int, double, String, object and other types of data:

method description
out.print (dataType dt) Value of output Type Type
out.println (dataType dt) Type Type of output value and then wrap
out.flush () Flush the output stream

session objects

javax.servlet.http.HttpSession session object is an instance of the class. And Java Servlets in the session object has the same behavior.

session object is used to track the session between each client request.


application objects

application objects directly packed ServletContext servlet class object is an instance javax.servlet.ServletContext class.

This object throughout the life cycle of the JSP page represents the JSP page. This object is created when the JSP page is initialized with the call jspDestroy () method was removed.

By adding attributes to the application, then all components of your web application JSP files can access these properties.


config objects

config object is an instance of the class javax.servlet.ServletConfig directly packed ServletConfig class objects servlet.

This object allows developers to access initialization parameters Servlet or JSP engine, such as file paths.

The following is the use of config object, not very important, it is not commonly used:

config.getServletName();

It returns contained in the <servlet-name> element in the servlet name, note, <servlet-name> element is defined in the WEB-INF \ web.xml file.


pageContext objects

pageContext javax.servlet.jsp.PageContext object is an instance of the class used to represent the entire JSP page.

This object is used to access the main page information while filtering out most of the implementation details.

This object stores a reference to the request and response objects. application objects, config objects, session objects, out objects can be derived by accessing the object's properties.

pageContext object also contains the instructions passed to JSP pages, including cached information, ErrorPage URL, the page scope like.

PageContext class defines a number of fields, including PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, APPLICATION_SCOPE. It also provides more than 40 kinds of methods, half inherited from javax.servlet.jsp.JspContext class.

One important way is removeArribute (), that accepts one or two parameters. For example, pageContext.removeArribute ( "attrName") Remove the four scope of the relevant properties, but this method is only to remove the following specific scope of the relevant properties:

pageContext.removeAttribute("attrName", PAGE_SCOPE);

page objects

This object is a reference to the page instance. It can be seen as representative of the JSP page.

page object is a synonym for this object.


exception objects

exception object wraps thrown exception information from the previous page. It is often used to generate an appropriate response to the error condition.