EL表达式、标签
来源:互联网 发布:飞思卡尔k60单片机 编辑:程序博客网 时间:2024/05/18 06:22
一、EL表达式
1 EL表达式获取前台传递过来的属性语法${}
2 只能获取通过setAttribute设置的值,不能修改值
3 如果想获取对象的属性则,直接通过点语法或者中括号的方
式来获取
如:
${user.name} 或者 ${user['name']}
注意:
点语法或者中括号里面的字段必须与该对象的属性名一致
二、标签
aglib的引入:
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
prefix:前缀
1、set
默认作用域是pageContext,仅当前页面,主要用来设置值,用getAttribute取值,也可以用${}
如:
<c:set var="name" value="zhangsan1" ></c:set>
<c:set var="name" value="zhangsan2" scope="request"></c:set>
<c:set var="name" value="zhangsan3" scope="session"></c:set>
<c:set var="name" value="zhangsan4" scope="application"></c:set>
2、条件语句
如:
<c:if test="${age%2!=0}">
3、forEach
如:
<c:forEach items="${list}" var="item" varStatus="statu">
<span>${statu.index}</span>
<span>${item}</span>
<br/>
</c:forEach>
想要设置list,需要用java代码,然后用setAttribute设置
三、自定义标签
1.建一个类,实现接口BodyTag
如:
package myweb_05_;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.Tag;
public class MyTage implements BodyTag {
private PageContext pageContext;
private String content;
private int times = 1;
public int getTimes() {
return times;
}
public void setTimes(int times) {
this.times = times;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public PageContext getPageContext() {
return pageContext;
}
@Override
public int doAfterBody() throws JspException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
return 0;
}
@Override
public int doStartTag() throws JspException {
JspWriter out = pageContext.getOut();
try {
for (int i = 0; i < times; i++) {
out.write("<h1>" + content + "</h1>");
}
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
@Override
public Tag getParent() {
// TODO Auto-generated method stub
return null;
}
@Override
public void release() {
// TODO Auto-generated method stub
}
@Override
public void setPageContext(PageContext arg0) {
// TODO Auto-generated method stub
pageContext = arg0;
}
@Override
public void setParent(Tag arg0) {
// TODO Auto-generated method stub
}
@Override
public void doInitBody() throws JspException {
// TODO Auto-generated method stub
}
@Override
public void setBodyContent(BodyContent b) {
// TODO Auto-generated method stub
}
}
2.建立.tld文件和web.xml放在同一个目录下
如:
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<description>我的新标签库</description>
<display-name>MY core</display-name>
<tlib-version>1.1</tlib-version>
<short-name>my</short-name>
<uri>http://java.tag.com/my</uri>
<tag>
<description></description>
<name>jereh</name>
<tag-class>myweb_05_.MyTage</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>content</name>
<required>true</required>
</attribute>
<attribute>
<name>times</name>
<required>false</required>
</attribute>
</tag>
</taglib>
3、使用
使用时引入:
如:
<%@ taglib uri="http://java.tag.com/my" prefix="m" %>
阅读全文
0 0
- EL 表达式 fmt标签
- EL表达式 & JSTL标签
- EL表达式...jstl标签
- EL表达式、JSTL标签
- EL表达式与标签
- EL表达式和标签
- strust 标签 el表达式
- EL表达式、Jstl标签
- EL表达式、标签
- EL表达式/JSP标签和EL表达式
- El表达式 自定义标签 El函数区别
- EL表达式和JSTL标签
- EL表达式和 JSTL标签
- 标签,el表达式的笔记
- el表达式和jstl标签
- EL表达式和JSTL标签
- EL表达式和JSTL标签
- EL表达式和JSTL标签
- 两个线程进行数据交换的Exchanger
- 关于xampp的默认目录 以及 修改问题
- 侧滑
- Mysql中的左连接、右连接的姿势
- android强大的SpannableStringBuilder
- EL表达式、标签
- CCF 分蛋糕 20170301
- PullToRefreshLayout
- java程序员的大数据之路(5):HDFS压缩与解压缩
- Oracle 存储过程
- HashSet的储存方式以及内存泄露的原因
- android的m、mm、mmm编译命令的使用
- Hive之 hive的三种使用方式(CLI、HWI、Thrift)
- Visualizing what ConvNets learn