JSP built-in objects

Source: Internet
Author: User

Application:

Let JSP, servlet share data: Application.setattribute (string name,object value) Set share property, Application.getatrribute (string name) Get the value of a shared property

Get web App configuration parameters

Config: current JSP configuration information

Exception: only valid on exception handling pages

Out: Page output stream

PageContext: Access to shared data between JSPs, including page, request, session, application range data

Set share properties: SetAttribute (String name, Object value,int scope)

GetAttribute (String name,int scope), scope has a value range of four, corresponding to page, request, session, application:

Page:PageContext.PAGE_SCOPE

Request:PageContext.REQUEST_SCOPE

Session:PageContext.SESSION_SCOPE

Application:PageContext.APPLICATION_SCOPE

Gets the range value of the property: Pagecontext.getattributesscope (String name)

Request: Encapsulates one user request per object

1. Can get the requested parameter, request header: (POST method submission)

Gets the name of the request header:

Enumeration<string> Headernames=request.getheadernames ();        while (Headernames.hasmoreelements ()) {String headername=headernames.nextelement ();     Out.println (headername+ "--" +request.getheader (headername) + "<br/>"); }

Get the data submitted by the form form:

String name=request.getparameter ("name");//name, color is the Name property of each data in form forms

String[] Color=request.getparametervalues ("color");//Get method when request parameter has multiple values

Get method commits: pass parameters as strings and pass parameters less URL way to pass parameters, parse strings with Chinese parameters: (Problem not resolved) string rawquerystr = Request.getquerystring ();  String querystr = Java.net.URLDecoder.decode (Rawquerystr, "utf-8");  String[] Parampairs=querystr2.split ("&");      for (String parampair:parampairs) {string[] namevalue=parampair.split ("=");         OUT.PRINTLN (namevalue[0]+ "parameter value:" +namevalue[1]+ "

String mytext = Java.net.URLEncoder.encode ("China", "utf-8"); String mytext2 = Java.net.URLDecoder.decode (MyText, "Utf-8");//mytext result is garbled and mytext2 result is "China"

2. Parameters for Operation request Range: SetAttribute (String name,object value); GetAttribute (String name);

3. Execute forward or include: (path path must start with a slash) Getrequestdispatcher (String path). Include (Request,respose); Getrequestdispatcher (String Path). Forward (Request,response);

Response: Generate a non-character response, redirect, increase Coolie Redirect, generate a second request, and the original requested parameter, request scope properties are all lost increase cookie:string name=request.getparameter ("  Name ");  Cookie C = new Cookie ("Usename", name); C.setmaxage (24*3600);//Set Cookie to 24 hours Response.addcookie (c);//Add Cookie Object

Read the Cookie array: cookie[] cookies = request.getcookies ();      for (Cookie c:cookies) {if (C.getname (). Equals ("Usename")) {Out.println (C.getvalue ()); }  }

Session: This object represents a user session SetAttribute (String name,object value); GetAttribute (String name);

JSP 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.