Introduction to jstl and El

Source: Internet
Author: User
Introducing jstl and El cannot help but introduce the standard action elements of JSP.
Standard action elements of JSP:
<JSP: usebean> Elements Using JavaBean
<JSP: getproperty> obtain a property value from a JavaBean Component and add it to the response.
<JSP: setproperty> set the attribute value of a JavaBean
<JSP: Include> the request processing stage contains the response from a servlet or JSP page.
<JSP: Forward> forward the processing of a request to a servlet or JSP page
<JSP: param> Add a parameter value to the request that uses <JSP: Include> or <JSP: Forward> to pass to another servlet or JSP page.
<JSP: plugin>

<JSP: attribute> set the action attribute value based on the object of this element.
<JSP: Body> set the Action Element body based on the body of the element. When an action element contains <JSP: attribute> action elements, <JSP: Body> is necessary.
<JSP: Element> dynamically generates an XML element. You can use nested <JSP: attribute> and <JSP: Body> actions to define attributes and bodies.
<JSP: Text> it is used to encapsulate the template text that needs to be used as is. It is usually only required on the JSP page written as an XML document.
Jstl is the JSP standard tag Library (jstl), and El is the expression language (EL ). This is part of JSP. Although sometimes it has the same functions as JSP action elements, the existence of each element is helpful, but its usage is not the same.
El OPERATOR:
. Access a bean property or map item
[] An array or list element
() Starts a subexpression to change the computational order.
? : Condition test: condition? Iftrue: iffalse
Empty empty variable test (null, empty string, or any array without elements, map or collection)
Func (ARG) function call. Here func is the function name, and Arg is a function parameter.
Implicit El variable
Pagination: a set of all page scope variables (Java. util. map)
Requestscope: a set of all request scope variables (Java. util. map)
Sessionscope:
Applicationscope:
Param: a set of all request parameter values (Java. util. Map). Each parameter corresponds to a string value.
Paramvalues: a set of all request parameter values (Java. util. Map). Each parameter corresponds to a string value.
Header: a set of all request header values (Java. util. Map). Each parameter corresponds to a string value.
Headervalues: a collection of all request header values (Java. util. Map). Each parameter corresponds to a string value.
COOKIE: a set of cookie values of all requests (Java. util. Map). Each cookie corresponds to a javax. servlet. http. Cookie value.
Initparam: a set of initialization parameter values of all applications (Java. util. Map). Each parameter corresponds to a string value.
Pagecontext: an instance of the javax. servlet. jsp. pagecontext class that provides access to various request data.

Use JSP/jstl/El to access JavaBean

Declare the bean On the JSP page and obtain the bean storage information.
<JSP: usebean id = "cartoon" Scope = "page" class = "com. ora... cartoonbean">

To set the JSP action attribute to the value generated by another action, you must use the following <JSP: attribute> Action Standard
<JSP: setproperty name = "MSG" property = "category">
<JSP: attribute name = "value" trim = "true">
<JSP: getproperty name = "mybean" property = "myproperty">
</Jsp: attribute>
</Jsp: setproperty>
Use El expression to process bean in JSP page


Set bean Properties
You can use the following two actions to set the values: <JSP; setproperty> or <C: Set>
Use the <JSP: setproperty> action
<JSP: usebean id = "MSG" class = ""> </jsp: usebean>

<JSP: setproperty name = "MSG" property = "category" value = "thoughts"/>
<JSP: setproperty name = "MSG" property = "category" value = "quotes"/>
Use the <C: Set> action
<C: set target = "$ {MSG}" property = "category" value = "thoughts"/>

JSP/jstl/El process user form input and user page output

Access parameter values using jstl actions
<Input type = "text" name = "username">
<Input type = "checkbox" name = "food" value = "Z">
<Input type = "checkbox" name = "food" value = "B">
<Input type = "checkbox" name = "food" value = "C">

Print related variable values:
<C: Out value = "$ {Param. Username}">
<C: foreach items = "$ {paramvalues. Food}" Var = "current">
<C: Out value = "$ {current}"/>
</C: foreach>

----------------------------------------------------------
Jstl <C: Out> attributes
Value: required. Added to the response value.
Escapexml: Boolean: Optional. If the special characters in the value should be rotated to the character entity code, the value is true. The default value is true.
Default: (optional) value used when the value attribute is null. It can also be defined by the body.
-----------------------------------------------------------
Jstl <C: foreach> attributes
Items: Optional. If it is specified, it is completely cyclic. Otherwise, you must specify begin and end.
VaR: (optional) Name of the variable that saves the current element value.
Varstatus: (optional) Name of the variable that saves the looptagstatus object.
Begin: (optional) The first index (starting from 0)
End: Optional. Last index (starting from 0)
Step: (optional) index increment during each iteration.
-----------------------------------------------------------
The request property of the implicit variable pagecontext, which can be accessed:
Authtype: name of the authentication mechanism to protect requests
Characterencoding :( string) Request body character encoding. null if unknown.
Contentlength: (INT) Length of the Request body. If not, it is-1.
Contenttype :( string) MIME type of the Request body
Contextpath: context path of the Request body
Cookies: (javax. servlet. http. Cookie []) Cookie requested by the customer
Locale :( java. util. locale) the customer's preferred localization Environment
Locales :( java. util. Enumeration) list of all user localization environments, sorted by preferred degree
Method :( string) Request Method
Protocol: protocol name and version
Remoteaddr: Customer IP Address
Remotehost: the host name of the client. If it is unknown, the IP address is displayed.
Remoteuser: the user name used to send the request if the page is protected. Otherwise, the value is null.
Requesturi: Request URI, for example:/APP/page. jsp
Requesturl: The request URL, for example, http: // server/APP/page. jsp.
Scheme: mechanism, such as HTTP or HTTPS
Servletpath: The relative path of the Request context, for example,/page. jsp.
Servername: Server Name
SERVERPORT: Port
Secure: true if a request is established on a secure channel (SSL.
Userprincipal :( java. Security. Principal) if the page is protected, it indicates that the user has created the principal of the request. Otherwise, it is null.
Bytes ----------------------------------------------------------------------------------------
Use bean to capture parameter values
<JSP: usebean id = "userinfo" class = "">
<JSP: setproperty name = "userinfo" property = "*"/>
</Jsp: usebean>
Bytes ---------------------------------------------------------------------------------------

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.