JSP nine large built-in objects

Source: Internet
Author: User
Tags map class

<div id="Request">

1. Get request Parameter value

<%

String id=request.getparameter ("id");

String name=request.getparameter ("name");

%>

2. Solve the Chinese garbled problem (the request text encoding method inconsistent caused by

You will need to reconstruct a string object with the specified encoding type using the string constructor method to correctly display the Chinese information)

<a href="Show.jsp?name=<%=urlencoder. encode (" no words ")%>

&sex=<%=urlencoder. encode (" male ") %>"> Solve Chinese garbled problem </a>

Name parameter value: <%=new String (Request.getparameter ("name"). GetBytes ("iso-88591"), "GBK")%>

Sex parameter value: <%=request.getparameter ("Sex")%>//garbled problem

3. Get Form form Information

<%=request.getparameter ("")%>

<%=request.getparametervalues ("")%>

4. Get Request Client Information

5. Managing information in the scope

<%=request.setattribute ("", "")%>

<%=request.getattribute ("")%>

6.cookie Management

7. Get the language used by your browser

</div>

<div id="Response">

Represents a response to the client that is valid within the JSP page

1. REDIRECT Web pages

<%response.sendredirect ("www.zhanwkj.com");%>

2. Handling HTTP File headers

<%response.setheader ("Refresh", "5"); 5 Seconds Auto Refresh once%>

<%response.setheader ("Refresh", "2; Url=welcome.jsp "); Skip to the specified page after 2 seconds%>

<%response.setcontenttype ("text/html"); %>

3. Setting the output buffer

<%response.setbuffersize (0);%>

</div>

<div id="session">

The server automatically creates the object associated with the user request, and the session object uses the map class to hold the data

1. Create and get session information

<%

String sessionmessage= "www.zhanwkj.com";

Session.setattribute ("message", sessionmessage);

%>

<%= (String) session.getattribute ("message")%>

2. Remove the specified binding object from the session

<% session.removeattribute ("message");%>

3. Destroying session Objects

<%session.invalidate ();//The Session object cannot be used after a call%>

4.Session Session Timeout Management

Generally speaking, the session life cycle in 20-30 minutes

<%session.setmaxinactiveinterval (1000);//Set session is valid for 1000s%>

</div>

<div id="Application">

Similar to global variables, information can be stored in the server until the server is shut down.

Otherwise, the information stored in the Application object will be valid throughout the application

1. Accessing Application initialization Parameters

Provides methods for accessing application environment properties

<%application.getinitparameter ("");%>

<%application.getattributenames (); %>

2. Managing Application Environment Properties

</div>

<div id="Out">

1. Managing Response buffering

2. outputting data to the client

</div>

Gets the session-scoped PageContext object

Get config object for Web. XML configuration Information

Gets the exception object for the exception

JSP nine large built-in objects

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.