<!-- userbean标签的标签体只会在实例化bean时才执行 -->
<%
pageContext.setAttribute("person",new Person());
%>
<jsp:useBean id="person" class="cn.itcast.domain.Person">
yyyy
</jsp:useBean>
<%=person.getName() %>
jstl+ el获取数据
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>My JSP '6.jsp' starting page</title>
<style type="text/css">
.even{
background-color: #CCCCFF;
}
.odd{
background-color: #CC99FF;
}
tr:hover{
background-color: #FFFF33;
cursor:hand;
}
</style>
</head>
<br/>------------------c:catch-------------------<br/>
<c:catch var="exception">
<%
int x = 1/0;
%>
</c:catch>
${exception.cause }<br/>
${exception.message }<br/>
${exception.stackTrace }<br/>
<br/>------------------c:if-------------------<br/>
<c:if var="a1" test="${sessionScope.user==null}"></c:if>
${a1 }
<br/>------------------c:foreach-------------------<br/>
<c:forEach var="num" begin="1" end="10">
${num }
</c:forEach>
<br/>------------------c:foreach实现表格间色-------------------<br/>
<%
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
list.add("ddd");
list.add("eee");
list.add("fff");
request.setAttribute("list",list);
%>
<table border="1" width="20%">
<c:forEach var="str" items="${list}" varStatus="status">
<tr class='${status.count%2==0?'even':'odd' }'>
<td>${str }</td>
</tr>
</c:forEach>
</table>
<br/>------------------c:url-------------------<br/>
<c:url var="url" value="/1.jsp">
<c:param name="username" value="中国"/>
<c:param name="password" value="123"/>
</c:url>
<a href="${url }">点点</a>
<c:url value="/2.jsp"/>
<br/>------------------c:fortokens-------------------<br/>
<%
String s = "aaa,bbb,ccc";
request.setAttribute("s",s);
%>
<c:forTokens var="str" items="${s}" delims=",">
${str }
</c:forTokens>
国际化标签和el函数库
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>sun el函数库</title>
</head>
<body>
${fn:trim(" aaa ") }
<br/>------------------------------------<br/>
<%
List list = new ArrayList();
list.add("aaa");
list.add("bbb");
list.add("ccc");
request.setAttribute("list",list);
%>
<c:forEach var="num" begin="0" end="${fn:length(list)}">
${list[num] }<br/>
</c:forEach>
${fn:length("aaaa") }
<br/>------------------------------------<br/>
${fn:split("aaa,bbb,ccc",",")}
<c:forEach var="str" items=''>
${str }
</c:forEach>
<br/>------------------------------------<br/>
<%
String arr[] = {"aaa","bbb","ccc"};
request.setAttribute("arr",arr);
%>
${fn:join(arr,"-") }
<br/>------------------------------------<br/>
${fn:escapeXml('<a href="">点点</a>')}
</body>
</html>