当前位置:网站首页>El expression and JSTL
El expression and JSTL
2022-06-12 07:55:00 【Watermelon 77】
What is? javaBean:
It is java Components commonly used in development , It's really just a java class , Its function is to encapsulate data .
Writing JavaBean Five specifications need to be met :
1. This java class , By public modification
2. This java Class should provide a public parameterless constructor
3. To provide private properties
4. To provide public for private properties set perhaps get Method
5. To achieve Serializable Interface
Be careful :
1.EL Case sensitive
2. Use EL front , You must first store the object in the scope . Saving objects to scope does not copy objects , Scope values hold references to objects , So it has little impact on the performance of the server .
Use EL expression
1. Defining variables
2 Put variables in request in
3 Use EL expression
Scope Range Scope
u s e r n a m e And {username} And username And {requestScope.username} It means the same thing
Use EL Access scope
1 Request scope :${requestScope.news}
2. Conversation scope :${sessionScope.username}
3. Program scope :${applicationScope.count}
4. Page scope :${pageScope.userNum}
Use JSTL expression
JSTL yes JSp Short for standard label library , It provides a label that can replace... To some extent java Code , for example <c:forEach/> Tags can achieve java The circular function in language .
1. download jstl.jar and standard.jar package
2 Copy these two packages to web-inf\lib Under the table of contents
3. stay JSp Add instructions to the page , for example :
<%@taglib uri=“http://java.sun.com/jsp/jstl/core” prefix=“c”%>
<c:out value="value"default=“default” escapXml=“ture” default=“0”> Used to change the meaning of tags in the database ;escapXml="ture " Can change one's mind false Don't change your mind .default Set text defaults
One . Relating to display operations
<c:out value=" ${ news.title }"/> The value of the output property The tags given in the database can show ;
<c:set var=“uid” value=“admin” scope=“request”/> Storing variables
hold uid The variables of are stored in request in
<c:remove var=“uid” value=“admin” scope=“request”/> Remove Variable hold request Medium uid Remove the variable of
Two . Implement program logic related
<c:forEach var=“ object ” items=” Save in request In the array " varStatus=“status”> Loop variables <c:forEach />
<c:forEach> Tags have some of the following properties :
var: The name of the iteration parameter . The name of the variable that can be used in the iteration body , Used to represent each iteration variable . The type is String.
items: The set to iterate over . The types it supports will be explained below .
varStatus: The name of the iteration variable , Used to represent the state of the iteration , You can access the iteration's own information .
begin: If you specify items, So iteration starts from items[begin] Start iterating ; If not specified items, Then from begin Start the iteration . It's of type integer .
end: If you specify items, Then in items[end] End iteration ; If not specified items, Then in end End iteration . It's also of type integer .
step: Step length of iteration .
<c:forEach> Labeled items Property support Java All standard collection types provided by the platform . Besides , You can use this operation to iterate over arrays ( Including basic type array ) The elements in . The collection types it supports and the elements of the iteration are as follows :
java.util.Collection: call iterator() To get the elements . java.util.Map: adopt java.util.Map.Entry Examples obtained .
java.util.Iterator: Iterator elements .
java.util.Enumeration: Enumeration elements .
Object Instance array : Array elements .
Basic type value array : Wrapped array elements .
Delimited by commas String: Split substring .
javax.servlet.jsp.jstl.sql.Result:SQL Query the row obtained .
Whether it's iterating over integers or sets , <c:forEach> Of varStatus Attributes play the same role . and var Same property ,varStatus Used to create scoped variables ( The amount of change only works in the current label body ). however , from varStatus The variable named by the attribute does not store the current index value or the current element , But to give javax.servlet.jsp.jstl.core.LoopTagStatus Class . This class contains a series of features , They describe the current state of the iteration , The meanings of these attributes are as follows :
current: For the current iteration ( In the collection ) term .
index: The current iteration starts from 0 The initial iteration index .
count: The current iteration starts from 1 The number of iterations started .
first: Used to indicate whether the current iteration is the first iteration , The attribute is boolean type .
last: Used to indicate whether the current iteration is the last one , The attribute is boolean type .
begin:begin The value of the property .
end:end The value of the property
step:step The value of the property
utilize varStatus attribute :
There is a pure way to desplay chekbox with two collums in jsp page.
checkboxLists yes checkBoxTO Set , contain key,value,checke attribute .
Java Code
Copy code
1 <c:forEach items=" c h e c k b o x L i s t " b e g i n = " 0 " s t e p = " 2 " v a r S t a t u s = " s t a t u s " > 2 < t r > 3 < t d > < c : o u t v a l u e = " {checkboxList}" begin="0" step="2" varStatus="status"> 2 <tr> 3 <td><c:out value=" checkboxList"begin="0"step="2"varStatus="status">2<tr>3<td><c:outvalue="{status.index}"/><input type=“checkbox” value=’<c:out value=" c h e c k b o x L i s t [ s t a t u s . i n d e x ] . k e y " / > ′ 4 < c : i f t e s t = " {checkboxList[status.index].key}"/>' 4 <c:if test=" checkboxList[status.index].key"/>′4<c:iftest="{checkboxList[status.index].checked eq true}">checked=“checked”</c:if>
5 /><c:out value=" c h e c k b o x L i s t [ s t a t u s . i n d e x ] . v a l u e " / > 6 < / t d > 78 < t d > < c : i f t e s t = " {checkboxList[status.index].value}"/> 6 </td> 7 8 <td><c:if test=" checkboxList[status.index].value"/>6</td>78<td><c:iftest="{!empty checkboxList[status.index+1]}">
9 <c:out value=" s t a t u s . i n d e x + 1 " / > < i n p u t t y p e = " c h e c k b o x " v a l u e = ′ < c : o u t v a l u e = " {status.index+1}"/><input type="checkbox" value='<c:out value=" status.index+1"/><inputtype="checkbox"value=′<c:outvalue="{checkboxList[status.index+1].key}"/>’
10 <c:if test=" c h e c k b o x L i s t [ s t a t u s . i n d e x + 1 ] . c h e c k e d e q t r u e " > c h e c k e d = " c h e c k e d " < / c : i f > 11 / > < c : o u t v a l u e = " {checkboxList[status.index+1].checked eq true}">checked="checked"</c:if> 11 /><c:out value=" checkboxList[status.index+1].checkedeqtrue">checked="checked"</c:if>11/><c:outvalue="{checkboxList[status.index+1].value}"></c:out>
12 </c:if>
13
14
15 </c:forEach>
Copy code
${status.count} The values in are derived from 1 Began to increase
Copy code
<c:forEach var=“Books” items=" l i s t " v a r S t a t u s = " s t a t u s " > < t r > < t d > < i n p u t t y p e = " c h e c k b o x " n a m e = " b o o k I d " v a l u e = " {list }" varStatus="status"> <tr> <td><input type="checkbox" name="bookId" value=" list"varStatus="status"><tr><td><inputtype="checkbox"name="bookId"value="{status.count}" />
B o o k s . b o o k n a m e < / t d > < t d > {Books.bookname }</td> <td> Books.bookname</td><td>{Books.b_price }
B o o k s . s t o c k < / t d > < t d c l a s s = " t h u m b " > < i m g s r c = {Books.stock}</td> <td class="thumb"><img src= Books.stock</td><tdclass="thumb"><imgsrc={Books.image } />
</c:forEach>
Copy code
<c:if test=“ Conditions ” var=" Judge the result ” scope=“var Stored scope (session,request,response,application)”> Code block </c:if>
3、 ... and . and url Address related
<c:url value=“ The page you need to connect to ”>
<c:param name=“id” value="${news.id}"/>
</c:url >
<c:import url=“url”/>
Four . And date number formatting
<fmt:formatDate value="${news.createtime}" pattern=“yyyy-mm-ff hh:mm:ss”/> Format time
fmt:formaNumber/ Formatting Numbers
c Core tag library http//:java.sun.com./jsp/jstl/core
fmt internationalization / Format tag library http//:java.sun.com./jsp/jstl/fmt
x XML Tag library http//:java.sun.com./jsp/jstl/xml
sql Database tag library http//:java.sun.com./jsp/jstl/sql
fn Function tag library http//:java.sun.com./jsp/jstl/function
边栏推荐
- R language dplyr package mutate_ At function and one_ The of function converts the data type of a specified data column (specified by a vector) in dataframe data to a factor type
- R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、比较不同K值超参数下模型准确率(accuracy)
- Scoring prediction problem
- Multithread decompression of tar
- MSE (mean square error) calculation package function
- Improvement of hash function based on life game (continued 1)
- Leetcode notes: biweekly contest 70
- What is a good recommendation system?
- Visual studio code batch comment and uncomment
- Pytorch installation (GPU) in Anaconda (step on pit + fill pit)
猜你喜欢

Summary of semantic segmentation learning (I) -- basic concepts

Topic 1 Single_ Cell_ analysis(3)

Some summaries of mathematical modeling competition in 2022

Generalized semantic recognition based on semantic similarity

Symfony 2: multiple and dynamic database connections

Scoring prediction problem

Bi skills - beginning of the month

L'effet de l'oie sauvage sur l'économie numérique verte de Guilin

Support vector machine (SVM)

Voice assistant -- Architecture and design of Instruction Assistant
随机推荐
2021.10.31-11.1 scientific research log
Leetcode notes: biweekly contest 71
Leetcode notes: Weekly contest 279
LeetCode笔记:Weekly Contest 295
Scoring prediction problem
2021.10.29-30 scientific research log
WEB页面性能优化面试题
R语言使用neuralnet包构建神经网络回归模型(前馈神经网络回归模型),计算模型在测试集上的MSE值(均方误差)
Classic paper review: palette based photo retrieval
AJ project: online bank project summary
Conda創建虛擬環境報錯,問題解决
Compiling principle on computer -- function drawing language (III): parser
Chapter 3 - Fundamentals of cryptography
R语言使用RStudio将可视化结果保存为pdf文件(export--Save as PDF)
The latest hbuilderx editing uni app project runs in the night God simulator
L'effet de l'oie sauvage sur l'économie numérique verte de Guilin
Summary of semantic segmentation learning (I) -- basic concepts
NaiveBayes function of R language e1071 package constructs naive Bayes model, predict function uses naive Bayes model to predict and reason test data, and table function constructs confusion matrix
Kalman filter encapsulation function
20220524 backbone deep learning network framework