Jsp/servlet Web Learning Note daythree

Source: Internet
Author: User

JSP built-in objects

Using JSP syntax, you can access these built-in objects to perform the servlet environment interaction of JSP Web pages. Built-in objects are actually generated by a particular Java class. Each built-in object is mapped to a specific Java class or port, which is generated automatically as the server runs.

The following table lists all the JSP built-in objects:

Object Name Describe Scope Classification
Appliction Display the corresponding page is an object with an application Entire application execution period Scope Communication objects: retrieving servlet-related information for JSP pages
Session All individual objects that hold personal information Session period
PageContext Provides an object that invokes other object methods During page execution
Out Represents the output data flow object that is opened by the server side to the client During page execution Input and Output objects: Controlling the input and output of the page
Request The object that contains the client request information User Request Period
Response Contains the appropriate content objects sent from the server side to the client Page Execution (response) period
Page Object that displays the current page During page execution Servlet object: Provides information about the environment of a page
Config JSP page initializes the received object through the container During page execution
exception Exception object generated when an error occurs During page execution Error object: Handling Errors in the page

  

1) Scope Communication Object

Radius: pagecontext<session<appliction

A) PageContext object

Provides access to all the built-in objects defined in the scope of the current page, commonly used in the following ways:

/* Store the value of an object in PageContext as a name/value */ void SetAttribute (String name,object Value) /* gets the value of the stored object in the Pageconetxt according to the name */ void getattribute (String name)
b) Seesion Object

Used to save and track the user's session state, common methods are the same as PageContext.

c) Application Object

Acting on the entire English program, all client windows can share the object, from the beginning of the server exists, until the server shuts down, the common method is pageconext the same.

2) Input Output object a) Request object

The client request, which contains all the request information, is commonly used as follows:

/* get the data submitted by the request page based on the page form component name */ string GetParameter (string name); /* get a form component in a page request that corresponds to multiple user request data (check box, etc.) */ string Getparametervalues (string name); /* get all client-to-server parameter names */ enumeration Getparameternames ();
b) Response Object

Handling the response generated by the JSP and sending the response results to the client is commonly used as follows:

/* set the type and character encoding as the corresponding generated content */ void setContentType (String name); /* send a corresponding to the browser, indicating that it should request another URL (redirect to another URL, will lose the data, jump no longer execute the code below the Sendredirect method) */ void sendredirect (String name); /* returns the output stream object to the client */ Getoutputstream ();
c) Out Object

Represents the output stream, which is sent to the client as requested, in common methods: print (), println (), write ().

    Out is rarely used in program code because the JSP expression is automatically placed in the output stream without having to explicitly point to the out output.

3) Servlet object a) Page object

Provides access to all objects defined on a Web page, representing the page itself, equivalent to the This keyword in Java .

b) Config object

The Config object stores some initial information about the servlet. The Config object represents the configuration of the servlet initialization data that compiles the JSP page.

4) Error Object exception

Handles errors in JSP pages that can be used only on the error page (pages where the page directive contains iserrorpage= "true") .

On the error page, use <%=exception.getmessage ()%> to get the error message.

Exception handling for JSP

If an exception occurs while executing the JSP Java code, you can forward the HTTP request to another specially processed Web page by using the following instruction:

<%@ page errorpage= "errorpage.jsp"%>

And in the Web page that handles the exception, the following statement should be:

<%@ page iserrorpage= "True"%> is also declared in.

In the Web page that handles the exception, you can directly access the exception implicit object for a detailed exception message.

  

Jsp/servlet Web Learning Note daythree

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.