, EL-. EL . , Integer, Integer ( ).
JSP- , Web- . :
request . , javax.servlet.http.HttpServletRequest. , HTTP, javax.servlet.ServletRequest. .
response . , javax.servlet.http.HttpServletResponse. , HTTP, javax.servlet.ServletResponse. .
pageContext JSP- . javax.servlet.jsp.PageContext. .
session HTTP javax.servlet.http.HttpSession, , . .
application , JSP-, javax.servlet.ServletContext. .
out . ,
, . javax.servlet.jsp.JspWriter. .
config javax.servlet.ServletConfig. .
page this java.lang.Object. .
exception java.lang.Throwable, .
JSTL core
JSTL : core, fomatting, SQL sql, XML xml.
Library | Actions | Description |
core | : if/then switch ; ; ; JavaBeans ; ; ; URL . | |
formatting | : ; ; , , . | |
sql | : ; , ; . | |
xml | XML- : XML; XML XPath XSLT. |
core .
|
|
<%@taglib uri=http://java.sun.com/jstl/core prefix=c %> JSP.
<jsp:root version=1.2 xmlns:c= http://java.sun.com/jstl/core >...</jsp:root> XML JSP.
:
<c:out /> ;
< c:set /> ;
<c:remove /> ;
<c:catch /> .
:
<c:if /> , true;
<c:choose /> (<c:when />, <c:otherwise />) <c:if /> , .
:
<c:forEach /> ;
<c:forTokens /> .
URL:
<c:redirect /> URL;
<c:import/> JSP WEB-;
<c:url /> request.getContextPath().
<c:param /> , <c:url/>.
, core.
<!-- #5: c:set, c:remove, c:if, c:out: core1.jspx -->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
version="2.0">
<jsp:directive.page contentType=
"text/html; charset=Utf-8" />
<html><head><title> core</title></head>
<h3> c:set, c:remove, c:if, c:out <br/></h3>
<form>
:<input type="text" name="set" /> <br/>
:<input type="checkbox" name="del" /> <br/>
<input type="submit" name="send" value=""/><br/>
</form>
<c:if test="${not empty param.send }">
<c:if test="${not empty param.set }">
<c:set var="item" value="${param.set}"
scope="session"></c:set>
</c:if>
<c:if test="${not empty param.del }">
<c:remove var="item"/>
</c:if>
</c:if>
<c:if test="${not empty item }">
<jsp:text> :</jsp:text>
<c:out value="${item }"/>
</c:if>
<c:if test="${empty item and not empty param.send}">
<jsp:text> : </jsp:text>
<c:out value=""/>
</c:if>
</html>
</jsp:root>
<!-- # 6: c:forEach, c:choose, c:when, c:otherwise: core2.jspx -->
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
|
|
xmlns:c="http://java.sun.com/jsp/jstl/core"
version="2.0">
<jsp:directive.page contentType=
"text/html; charset=Utf-8" />
<html><head>
<title> core</title>
</head>
<h3> <br/>c:forEach, c:choose, c:when, c:otherwise</h3>
<jsp:text> <br/> 50: <br/></jsp:text>
<jsp:useBean id="arr" class="chapt21.Arr" />
<c:set var="items" value="${arr.fillMap}"
scope="session" />
<c:forEach var="id" items="${items}">
<c:out value="${id}" />
<c:choose>
<c:when test="${id > 50}" >
<c:out value=" - 50"/>
</c:when>
<c:otherwise>
<c:out value=" - 50"/>
</c:otherwise>
</c:choose>
<br/>
</c:forEach>
</html>
</jsp:root>
JavaBean, , Arr, . Arr.java. Java- ( build, src JavaSourse) web-. class chapt21.Arr jsp:useBean , chapt21, Arr. EL- arr.fillMap getfillMap().
// # 7: javabean : Arr.java
package chapt21;
public class Arr {
public Arr(){}
public String[] getfillMap(){
String str[] = new String[5];
for (int i =0; i < str.length; i++){
String r = Integer.toString((int)(Math.random()*100));
str[i] = r;
}
return str;
}
}
:
1)
c:forEach, c:choose, c:when, c:otherwise
50:
8 - 50
68 - 50
84 - 50
5 - 50
36 - 50
.
<!-- # 8: c:import, c:url, c:redirect, c:param: url.jsp -->
<%@ page language="java" contentType=
"text/html; charset=Cp1251"
pageEncoding="Cp1251"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>
<html><head><title> </title></head>
<body>
<h3> <br/>c:import, c:url, c:param, c:redirect</h3><br/>
<c:import url="\WEB-INF\jspf\imp.jspf"
charEncoding="Cp1251"/>
<c:url value="redirect.jspx" var="myUrl" />
<a href='<c:out value="${myUrl}"/>' /></a>
</body></html>
<!-- # 9: , c:import (
WEB-INF/jspf/): imp.jspf -->
<h5>importing by using c:import from jspf</h5>
url.jsp :