Home  >  Article  >  类库下载  >  What are the built-in objects of JSP?

What are the built-in objects of JSP?

清浅
清浅Original
2019-04-16 10:34:505473browse

The built-in objects in JSP include: out application, request application, access customer data, response application, session application, application application, obtaining configuration objects in web.xml, obtaining exception information, etc.

JSP built-in objects are abstractions based on JSP functions. Any JSP page is included in output, request, response, context and exception handling. Next, I will introduce the built-in objects in JSP in detail in the article, which has certain reference value. I hope it will be helpful to everyone

What are the built-in objects of JSP?

[Recommended courses: JSP Tutorial

1. out application

(1) Data is output to the client, providing the print() method and println() method

Example:

 out.print("abc")
 out.println("abc")

(2) Buffer management, mainly cleaning, refreshing buffer and buffer size

Methods include: clear(), clearBuffer(), flush(), getBufferSize()

2. request application

(1) Get request parameters: send the form of hyperlink in the request, And add one at the end? To achieve

Example:

<a href="***? id=1">

The value of the ID can be accessed through the getParameter() method in the request object

(2)Chinese garbled characters

When accessed When the request parameters are garbled, you can use the following code to solve the problem

String user= new String (request.getParameter ("user").GetBytes ("ISO-8859-1"), "UTF-8")

When the access form parameters are garbled, you can use the following code to solve the problem

 request.setCharacterEncoding ("UTF-8");

3. Access customer data

The client obtains available relevant information through the request object. Such as HTTP header, client mode, host address, port number, etc.

Methods: getHeader(), getMethod(), getProtocol(), getRemostHost(), getCookies()

4. Response application

(1) HTTP header information operation: set response type, disable cache, set automatic page jump, page refresh and timing

Disable cache:

 response.setHeader("Cache-control","no-store")
 response.setDateHeader("Expires",0);

Auto refresh:

response.setHeader("refresh","10")

Timed jump:

response.setHeader("refresh","2;URL=login.jsp")

(2) Set the MIME type

Use the following code to output the content of the web page to the browser in different forms

response.setContentType (String type);

(3) Page reload Directing

Redirects a web page to another page using the response object provided by the sendRedirect() method. For redirection, the attribute in the request fails, and the beginning of the new request object

Example:

response.sendRedirect(String path)

5. Application of session

(1 )session life cycle

(2) Create and obtain the session

The session object can store or read customer-related information, and obtain the session object through the setAttribute() and getAttribute() methods

session.setAttribute(String name,Object obj);
session.getAttribute(String name);

Note: getAttribute returns an Object type, you can enter coercion or toString() method

(3) Delete session

Implemented through session.removeAttribute(String name); method

(4) Setting up session within valid time

6, application application

(1) Life cycle

(2) Data operation

Attributes can be stored in the application object, read or delete the application method

setAttribute(): Store the attribute in the request

getAttributeName(): use the attribute Name

getAttribute(): Get the attribute value

removeAttribute(): Get the configuration object from the specified application object name

7. Get the configuration object in web.xml

The config object is mainly used to obtain server configuration information. You can obtain getServletConfig (Implementation) in pageContext.

Common methods:

getInitParameter( ): used to initialize parameters

getServletName(): access the Servlet server name

getServletContext( ) to obtain the Servlet context

8. Get exception information

Exception objects are mainly used to handle JSP file execution errors and exceptions. The main methods are:

getMessage(): Return an exception information string

getLocalizedmessage() returns localized errors

Summary: The above is the entire content of this article, I hope it will be helpful to everyone

The above is the detailed content of What are the built-in objects of JSP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn