A Configure JSTL
Includes two JAR files, Jstl.jar and Standard.jar. What is not necessary tube, heavy in the application (A. =2, we have no need to delve into this, just know how to use it. )。
Original introduction:
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix= "sql" uri= "Http://java.sun.com/jsp/jstl/sql"%>
<%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>
Two Core Tag Library
The core tag library mainly includes general-purpose labels, condition tags, iteration labels, and URL-related tags. To use the Core tag on the JSP page, to use the Taglig directive, specify the referenced tag library as follows:
<%@ taglib rui= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
General-purpose labels include <c:out>, <c:set>, <c:remove>, <c:cath>
1.<c:out>
Used to evaluate an expression and output the result. Similar to the <%=%> expression in the JSP, or the $ ${el-expression} in EL.
2.<c:set>
Used to set the value of a range variable or the properties of a JavaBean object.
See a practical example:
<c:set var= "username" value= "Lisi" scope= "session"/>
This is equivalent to setting the session.
3.<c:remove>
Relative <c:set> Its role is to remove the range variable. For example: <c:remove var= "Nusername" scope= "Session"/>
4.<c:catch>
Used to capture the exception object thrown by the operation in which it is nested, and to save the exception information to a variable.
We will have the possibility to throw the exception code between the start tag:<c:catch> and the end tag:</c:catch>. If there is an exception in the code, the exception object is captured and stored in a VAR-declared variable that always has a page range. If no exception occurs, the range variable identified by Var is removed.
If the var attribute is not specified, the exception is simply captured and the exception information is not saved.
Eg:
<c:catch var= "Exception" >
<%
int i = 5;
int j = 0;
int k=i/j;
%>
</c:catch>
<c:out value= "${exception}"/><br>
<c:out value= "${exception.massage}"/>
The latter sentence is equivalent to: Exception.getmessage ()
Condition tags include <c:if><c:choose><c:when><c:otherwise>
1.<c:if>
Used to implement the IF statement functionality in Java.
<c:if test= "${user.visitcount==1}" >
This is your first visit.
</c:if>
If true, the middle section is printed. You can also declare Var to make it easier to decide next.
<c:if test= "${param.name== ' admin '}" value= "Result"/>
<c:out value= "${result}"/>
2.<c:choose>
<c:choose> and <c:when>, <c:otherwise> together implement mutually exclusive conditions, similar to if else in Java.
<c:choose> is generally used as the parent tag for <c:when>, <c:otherwise>.
Eg:
<c:choose>
<c:when test= "${row.v_money<10000}" >
Beginner
</c:when>
<c:when test= "${row.v_money>=10000&&row.v_money<20000}" >
Try your Skill
</c:when>
<c:otherwise>
Business expert
</c:otherwise>
</c:choose>
Iteration Labels
Iterations tagged with <c:forEach> and </c:forEach>
Traversing a recordset
<c:foreach items= "${finalresult.rows}" var= "Row" >
<tr class= "<%=tdclass[(rank+1)%2]%>" >
<TD align= "center" ><span><%=rank%> </span></td>
<TD align= "center" ><span ><c:out value= "${row.player_name}"/></span> </td>
<TD align= "center" ><span >¥<c:out value= "${row.money}"/></span></td>
</tr>
<%rank++;%>
</c:forEach>
You can also set a fixed number of times.
<c:foreach var = "I" begin= "end=" >
${i}
</c:forEach>
If you add another step= "2" then each increase is 2.
Three SQL Tags
To set up a data source:
<sql:setdatasource datasource= "Proxool.breadtycoon"/>
Declare the result of a database query as a variable
<sql:query var= "Finalresult" >
Select Player_name,money from Tb_player ORDER by Money DESC LIMIT 10
</sql:query>
You can then:
<c:foreach items= "${finalresult.rows}" var= "Row" varstatus= "S" >
Advcosts[${s.index}]=${row.adv_cost};
</c:forEach>
Data Update Label:
<sql:update>
Call Proc_set_role_salespro (?,?,?,?,?);
<sql:param value= "/>"
<sql:param value= "/>"
<sql:param value= "<%=spID%>"/>
<sql:param value= "<%=productID%>"/>
<sql:param value= "1"/>
</sql:update>
<sql:query var= "Queryallchannelcount" >
SELECT COUNT (*) as total from Tb_channel WHERE game_id=? and Begin_round<func_cur_round (?) and player_id=? and channel_flag=0
<sql:param value= "${gameid}"/>
<sql:param value= "${gameid}"/>
<sql:param value= "${playerid}"/>
</sql:query>
<c:foreach items= "${queryallchannelcount.rowsbyindex}" var= "CHANNELCN" >
<c:set value= "${channelcn[0]}" var= "Channeltotal"/>
</c:forEach>
Call the stored procedure to update the database:
<c:if test= "${param.changsubmit!=null}" >
<c:foreach items= "${paramvalues.pro_id}" var= "getpro_id" varstatus= "Getparamsta" >
<sql:update>
Call Proc_set_role_product (?,?,?,?,?,?,?,?);
<sql:param value= "${gameid}"/>
<sql:param value= "${playerid}"/>
<sql:param value= "${getpro_id}"/>
<sql:param value= "${getpro_id}"/>
<sql:param value= "${paramvalues.pro_sort[getparamsta.index]}"/>
<sql:param value= "${paramvalues.price[getparamsta.index]}"/>
<sql:param value= "${paramvalues.output[getparamsta.index]}"/>
<sql:param value= "0"/>
</sql:update>
</c:forEach>
</c:if>
Four Formatting labels
<fmt:formatnumber value = "12.3" pattern= "."/>
Will output 12.300. Applying the style ". 000" will make the formatted fractional portion have 3 bits. Less than 3 bits will be 0 padded.
<fmt:formatdate value= "<%=new java.util.Date ()%>" type= "Date"/>
The result of the formatting is: 2007-5-27.
<fmt:formatdate value= "<%=new java.util.Date ()%>" type= "Time"/>
The formatted result is: 9:25:11
<fmt:formatdate value= "<%=new java.util.Date ()%>" type= "both"/>
The result is formatted: 2007-5-27 9:25:11
Complementary points of knowledge:
1. Replace Request.getparameter ("test"):
<c:if test= "${param.test!=null}" >
<c:out value= "${param.test}"/>
</c:if>
2. <c:redirect url= "a.jsp" >
3.<c:redirect url= "/max.jsp" context= "/CH16" >
<c:param name= "name1" value= "665"/>
<c:param name= "Name3" value= "Stephen"/>
</c:redirect>
4.<c:fortokens items= "Zhangsan:lisi:as" delims= ":" var= "Name" >
${name}
</c:forTokens>
From:http://blog.sina.com.cn/s/blog_4550f3ca010143lb.html
Other:
The EL expression determines whether an object is empty, with the empty keyword, and, of course, in front of it. Represents not NULL, as an example:
<c:if test= "${empty mylist}" >mylist is empty </c:if>
<c:if test= "${!empty mylist}" >mylist not empty </c:if>
Use of Jstl tags