JSP expression Language El

Source: Internet
Author: User

JSP writes a script-free JSP page:
EL: Expressions language: Expression Language

El language as long as the goal is to remove Java code from the JSP page. Let the front-end to do the front-end, background focus backstage
El is used only for display purposes, such as if those cannot be used, defining variables cannot

To define a variable: Use a JavaBean property, an implicit object provided by the JSP, automatically with the tag library and the standard tag library


code example:
jsp:<%= user.getusername ()%> cannot object. Object. Properties
El:$<user.username> can object. Object. Properties, Presentation is simple
$<requestscope.user.username>
Placed in the Request object, Requestscope can be omitted


An implicit object:
Requestscope Correspondence Req
Applicationscope Correspondence ServletContext

The EL expression is in the Action object, way: Remember: Object. The property name of the object. Without the Get method or something.

Get the value of request
$<user.username>

Get the dynamic environment value
Applicationscope can access the JSP's implicit object application,request,response,session,out, etc.


Get ServletContext Initialize Environment value
${initparam.money}

Get the value of session
Req.getsession (). SetAttribute ("User2", "U14");
${sessionscope.user.username}

Gets the value of the collection: Map,list,set collection
list<userbean> users = new arraylist<userbean> ();
Users.add (user);
Req.setattribute ("UserList", users);

Map<string, userbean> maps = new hashmap<string,userbean> ();
Maps.put ("A1", user);
Req.setattribute ("UserMap", maps);

${requestscope.user[0].username}
${requestscope.usermap[' A1 '].username}

JSP custom tag library and standard Tag library Jstl
In the required interface, generally these two packages: Jstl.jar Standard.jar

<c:catch var= "Exception"/>
<% int x = 3/0; %>
<c:set var= "UNM" value= "s{4*2}"/>
<c:out value= "${num}" >
</c:catch>

<c:if test= "${exception! = null}" >
<p> this is an exception:${excption}</p>
</c:if>

Set
<c:set var= "UNM" value= "s{4*2}"/>
<c:set var= "UNM" value= "8"/>
Or
<c:set var= "num" >
${4*2}
</c:set>

We can manipulate objects returned in the background, set the value of the object
<c:set gerget= "${user}" property= "Age" value= "$"/>
<c:out value= "$user. Age"/>

Remove a property within a specified scope with the Remove tag
<c:remove var= "UserName" scope= "Request" >

Process Control:
Choose when equivalent to Swith case
<c:choose>
<c:when test= "${num < 5}" >
Not about
<c:when>

<c:when test= "${num > Ten}" >
About
<c:when>

<c:otherwise>
Gun
</c:otherwise>

</c:choose>

foreach: Loop, which is the Java foreach
<c:foreach items= "${user}" var= "U1" >
${u1.username},
${u1.password},.
${u1.age},
</c:forEach>

You can put it in the form.
<table border=1>
<tr>
<th> name </th>
<th> Age </th>
<th></th>
<th></th>
<th></th>
</tr>

<c:foreach items= "${user}" var= "U1" >
<tr>
<td>${u1.userName}</td>
<td>${u1.password}</td>
<td>${u1.age}</td>
<td></td>
<td></td>
</tr>
</c:forEach>


<table>

JSP expression Language El

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.