SP 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