Jsp Study Notes 1-built-in objects

Source: Internet
Author: User

Jsp Study Notes 1-built-in objects

 

Jsp built-in object

In jsp, nine built-in objects are:

1) out. 2) request. 3) response.4) session.5) application; // common
6) page 7) pageContext 8) exception 9) config // not commonly used

1. requset & response object

Use >>> request >>> web
User <response <server, which is called a request sent by the user to the server. The opposite is called a response ).

Similar to the intend object and handler object in Android development, request and response also encapsulate the information sent between the web server and the user.
In the form, use the following code to submit a request:

 

The action attribute specifies the page for processing the form. Method attribute specifies the submission method post | get.
Post is submitted in encrypted mode to submit the password. It is less efficient than get, but secure and has a large amount of data.
Get is submitted in plain text, which is suitable for processing search requests. The data size should not exceed 2 kb. URL:
Http://www.baidu.com? Wd = sjy & ie = UTF-8
Here is the submission in plain text. It is the URL of Baidu's sjy search in IE browser, and the search characters are encoded in UTF-8.

Common Methods for request objects include:
String getParameter (String name): returns the value of the parameter specified by name, similar to the get method of HashMap.
String [] getParameterValues (String name): returns all worthwhile arrays containing the parameter name.
Void setAttribute (String, Object );
Object getAttribute (String, Object);: stores/returns a property value.
String getCOntentType ()
String getProtocol ()
String getServerName () returns some server attributes

Common response methods include:
String getCharacterEncoding ()
Void setContentType (String type) to set the corresponding MINE type
SendRedirext (String location) Request redirection to redirect requests to the specified page
PrintWriter getWriter (): returns an object that can output characters to the client. It outputs out objects in advance and built-in out objects. You can use the out. flush () method to output out in advance.
Buffer content

 

Ii. session Object & application Object

The lifecycle of a session object starts when the user creates an access, ends when the user ends all access, and ends when the browser is closed. Session resident web Server Memory, used to store parameters during one access. It can be understood as a set of global variables during an access period.

Application, a global object, similar to the static object in Java, which can be called on all pages and sessions. It starts when the server is started and ends when the server is shut down. The same as session is used to store data, but the lifecycle is different.

Common session methods include:

Void setAttribute (String key, Object value)

Object getAttribute (String key): stores and sets attribute values.

Common application methods:

Void setAttribute (String key, Object value );
Object getAttribute (String key): stores and sets attribute values.

 

3. page Object & pageContext object

The page Object points to the jsp page itself, which is an instance of the java. lang. Object Class.

PageContext object
1) provides access to all objects and namespaces on the Jsp page.
2) You can obtain the session on this page.
3) this class of pageContext is also called pageContext.


Common pageContext methods:
JspWriter getOut (): obtains the JspWriter stream (out) corresponding to the current client)
HttpSession getSession (): returns the HttpSession object (session) on the current page)
Object getAttribute (String name, int scope): name attribute within the specified range.
Object getAttribute (String name): obtains the name attribute within the page range.
Void setAttribute (String name, Object value)
ServletRequest getRequest (): returns the ServletRequest object of the current page.
ServletResponse getResponse (): returns the ServletResponse object of the current page.

Void forward (String relativeUrlPath): Re-uploads the page to the previous page.
Void include (String relativeUrlPath): contains another file at the current position

 

Iv. exception object


To use exception in jsp, you must set attribute: isErrorPage = ture of the current page.
ErrorPage = exception. jsp exception handed over to exception. jsp for handling

Common Methods:

String getMessage ();
String toString ();
Void printStackTrace: returns a scene and stack track

 

 

 

Related Article

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.