9 built-in objects of JSP scripts

Source: Internet
Author: User

JSP's built-in objects are all Servlet API interface instances. Create instances in the _ jspService method of the Servlet generated by the JSP script (why is there no exception object? The exception object can be used only when the isErrorPage attribute of the page command in the page is true .), Therefore, we can use these built-in objects in JSP output expressions.

    _jspService( javax.servlet.http.HttpServletRequest request, = =  java.lang.Object page = = = 
1: application Object 1: Data is shared among multiple JSPs in the entire Web system. '2: Web application access parameter configuration.
<%!%><%"counter",String.valueOf(++%>
<%=application.getAttribute("counter") %>

 

Access the application variable in Servlet:

          service(HttpServletRequest request, HttpServletResponse response) "text/html;charset=GBK"=="counter"

 

Obtain the Web application configuration parameters:

<%application.getInitParameter("driver");application.getInitParameter("url");application.getInitParameter("username");application.getInitParameter("password");%>

Web. xml:

    <context-param>        <param-name>driver</param-name>        <param-value>com.mysql.jdbc.Driver</param-value>    </context-param>

 

 

2: output stream of the out object page
Service (HttpServletRequest request, HttpServletResponse response) "text/html; charset = GBK" = "nice to see and hate"

 

3: config object

Indicates the configuration information of the current JSP page, which is used less in JSP and more in Servlet.

 

4: exception object

Throwable instance, part of the JSP page exception mechanism.

JSP generates Servlet. All JSP scripts and static HTML will be placed in the try block. An exception occurs. If errorPage is specified, it will be forwarded to the specified error page, if not, an exception occurs on the current page.

 

5: pageContext object

Indicates the context to access Shared data between JSP. You can use the pageContext object to access objects in the range of application, request, session, and page.

GetAttribute (String name) gets the name attribute of page

GetAttribute (String name, int scope)

        <%%>

 

6: request object

The request object encapsulates a user request. The request object is an instance of the HttpServletRequest interface.

GetParameter ()

GetHeader ()

        <%<String> headerNames === request.getParameter(= request.getParameterValues(%>

 

 

The GET request contains Chinese characters.
        <%                                    String queryString =            String decoderString = java.net.URLDecoder.decode(queryString,  = decoderString.split(%>

 

7: response object

1: The response object generates a non-character response.

2: redirection.

        <%"target.jsp"%>

3: Add Cookie

        <%= request.getParameter("username"=  Cookie("username"6*24*60*60%>
        <%=("username"%>

By default, the Cookie value cannot contain Chinese characters. However, you can use URLEncoder to encode Chinese characters and save the encoded value as the Cookie value. When reading cookies, you should first read them and then use URLDecoder to decode them.

 

8: session Object

  

        <%"username", "harry"%>

 

9: page Object

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.