this blog is original: Integrated still Silicon Valley (http://www.atguigu.com) System tutorial (deep thank) and network of existing resources (blogs, documents, books, etc.), the source of resources I will markThe purpose of this blog: ① summary of their own learning process, equivalent to study notes ② to share their own experience to everyone, learn from each other, communication, not commercialcontent inevitably appear problems, welcome to correct, exchange, discussion, you can leave a message, can also be contacted by the following ways. I Internet technology enthusiasts, Internet technology enthusiastsWeibo: Ivan is in 0221qq:951226918
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -----------------------------
1. EL itself also has its own hidden object. EL Hidden Objects Total 11
2. Classification
1) Implied objects related to the range: Applicationscope sessionscope requestscope pagescope
2) Implied objects related to input:param paramvalues
3) Other hidden objects: Cookie header headervalues Initparam pagecontext
3. Details: Hidden objects related to the scope
1) The EL implied objects associated with the range contain the following four: Pagescope, Requestscope, Sessionscope, and Applicationscope, which are basically the PageContext, req, and the JSP Uest, session and application;
2) four hidden objects can only be used to obtain the range attribute value (the property set by the domain object), that is, getattribute (String name) in the JSP, but can not obtain other relevant information;
3) Note: The request object in the JSP can be accessed in addition to the properties, but also to obtain the user's requested parameters or header information, and so on. However, in EL, it can only be used to obtain the corresponding range of attribute values;
For example: We are going to store a property in the session whose name is username and use Session.getattribute ("username") in the JSP to get the value of username, but in EL, it is used ${ Sessionscope.username} to obtain its value.
①pagescope: The scope and JSP page is the same, that is, the scope of a single page JSP page (scope);
②requestscope: The scope is the same as the JSP request, and the scope of the Requestscope refers to the request from one JSP Web page to another, and then the property is invalidated;
③sessionscope: The scope is the same as the session in the JSP scope, and its attribute range is the time that the user continues to connect to the server;
④applicationscope: The scope is the same as the application in JSP scope, its property scope is the service from the beginning of the server, until the server shuts down;
Example code:
1 <% 2 new Date ()); 3 %> 4 <!--the range of hidden objects Related:-- 5 time:${applicationscope.time} 6< /c11> 7 equates to 8 <% 9 application.getattribute ("Time" ); Ten %> --%>
4. Explanation: Implicit objects related to input
1) Generally speaking, we can use the following methods when we obtain the user's request parameters;
Request.getparameter (String name)
Request.getparametervalues (String name)
2) in EL you can use Param and paramv alues both to get the data
${param.name}//Gets a request parameter named name
${paramvalues.name}//Gets a set of request parameters named name
Example: http://localhost:8080/javaWEB/el/el2.jsp?name=a&name=b&name=c&score=100 Note: As long as you get the type of the parameter, there is a get method that can be used all the way to get the other corresponding value or property
1 <!--implied objects related to input: param,paramvalues---2 3 <br>4 5 name:${paramvalues.name[1]}//Get a set of values with the same property name, with different property values, obtained by subscript, starting from 0
5. Explanation: Other hidden objects
1) Cookies (understanding, development rarely used)
The so-called cookie is a small text file, it is a key, value in the way the Session Tracking content in this text file, this text file usually exists in the browser's staging area. JSTL does not provide a cookie-setting action, because this action is usually something that the backend developer has to do, rather than handing it over to the front-end developer. If we set a value in the cookie named Usercountry, then we can use ${cookie.usercountry} to get it.
Cookie:${cookie}
2) Header and Headervalues (learn)
The header stores the data that the user's browser and the server use to communicate, and when the user requests the Web page of the server, it sends out a header file that records the requested information, such as the version of the user's browser, the area set by the user's computer, and other relevant data. If you want to get the version of the user's browser, that is ${header["user-agent"}. In addition, under rare opportunities, it is possible to have different values for the same header name, and you must instead use Headervalues to obtain these values. Because user-agent contains "-" This special character, you must use "[]" instead of a $ (header). user-agent).
Accept-language:${header}
3) Initparam
Just like other properties, we can set the environment parameters (context) of the Web platformourselves, and when we want to get these parameters, we can use the Initparam implicit object to get it, for example: when we set the following in XML.
1 <Context-param>2 <Param-name>Driver</Param-name>3 <Param-value>Com.mysql.jdbc.Driver</Param-value>4 </Context-param>5 <Context-param>6 <Param-name>Jdbcurl</Param-name>7 <Param-value>Jdbc:mysql:///test</Param-value>8 </Context-param>
Code in the JSP:
1 driver:${initparam.driver}<br><br>2 Jdbcurl:${initparam.jdbcurl}
The results show:
1 Driver:com.mysql.jdbc.Driver 2 3 Jdbcurl:jdbc:mysql:///test
4) PageContext (that is, the Pagecontex type, but can read the properties, you can always pass.) The way to get the property value)
We can use ${pagecontext} to get additional details about user requirements or pages
${pagecontext.request.querystring} Gets the requested argument string
${pagecontext.request.requesturl} Gets the requested URL, but does not include the request's argument string
${pagecontext.request.contextpath} the name of the Web application of the service
${pagecontext.request.method} Method of getting HTTP (GET, POST)
${pagecontext.request.protocol} Get the protocol used (http/1.1, http/1.0)
${pagecontext.request.remoteuser} Get user name
${pagecontext.request.remoteaddr} get the IP address of the user
${pagecontext.session.new} Determines whether the session is a new, so-called New session, which indicates that the client has not yet been used because it was created by the server
${pagecontext.session.id} Gets the ID of the session
${pagecontext.servletcontext.serverinfo} access to host-side service information
Code in the JSP:
1 <BR>2 PageContext is the Pagecontex type, but can read the property, it can always go through the way to get the property value3 <!--PageContext -4 5 <BR>6 Contextpath:${pagecontext.request.contextpath}7 <BR>8 <BR>9 Sessionid:${pagecontext.session.id}Ten <BR> One <BR> A Sessionattributenames:${pagecontext.session.attributenames} - <BR>
Results:
1
2
3
[11 Hidden objects in the original]java Web learning Note 38:el