Hidden objects and 4 scope objects in JSP page 9 __js

Source: Internet
Author: User
Implied object of the JSP:
A set of objects that can be used directly without the need for new.
Tomcat is created automatically and can only be used in expression script <%=%> and normal script <%%>.
1, request "key"
Type: javax.servlet.http.HttpServletRequest
Methods: Request.getparameter ("txtUserName");
Request.setcharacterencoding ("GBK");
Request.setattribute (String, Object)
Request.getattribute (String);
Request.getsession (TRUE);
Request.getrequestdispatcher ("/url-pattern");
Request.getcookies ();
2, session "key"
Type: javax.servlet.http.HttpSession
Method: Session.getid ()
Session.setattribute (String, Object)
Session.getattribute (String)
Session.removeattribute (String)
Session.invalidate ()
Start: Session begins when client issues a JSP request for the 1th time
End: Timeout, invalidate ()
3, Response
Type: Javax.servlet.http.HttpServletResponse
Methods: Response.setcontenttype ("text/html");
Response.getwriter ();
Response.setcharacterencoding ("GBK");
Response.sendredirect ("/web Application name/url-pattern");
4, out
Type: Javax.servlet.jsp.JspWriter
Method: Out.print ()//to IE print
OUT.PRINTLN ()//To IE print, add line wrap in source code
Out.write ()//to IE print, usually user print constant
5, Application
Type: Javax.servlet.ServletContext
Method: Application.getinitparameter ("name");
Application.setattribute (String, Object)
Application.getattribute (String)
Application.removeattribute (String)
6, page
Type: Java.lang.Object
Represents the current JSP page, can be understood as this,jsp is a special servlet class, generate JSP page also generates the corresponding servlet instance. The page represents the current Servlet object instance and is not normally used.
7, Config
Type: Javax.servlet.ServletConfig
8, exception
Type: java.lang.Throwable
You can only use the JSP in the <%@ page iserrorpage= "true"%>.
9, PageContext




It's a PageContext object, PageContext is a jspcontext subclass.




1 Other 8 hidden objects can be obtained
JspWriter o = pagecontext.getout ();
2 scope (JSP in a total of 4 scope objects, from small to large: PageContext, request, session, application)
A page in the current request
Type: Javax.servlet.jsp.PageContext
Method: Pagecontext.setattribute (String, Object);
Pagecontext.getattribute (String);
3 can access named properties in the other 3 scopes
Search for named properties specified from 4 scopes from small to large, stop
Method: Pagecontext.findattribute (String);//jspcontext inside the method
Get named property from specified scope
Pagecontext.getattribute ("name", Pagecontext.application_scope)

4) Include/forward


JSP four scoping objects

Pagecontext,request,session,application


Servlet Three Scope objects

Request,session,application


Four scope objects in El

Pagescope,requestscope,sessionscope,applicationscope

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.