2008年4月16日

JSTL Scope

JSP(tm) Standard Tag Library 1.1 implementation

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<c:set var="sessionKey" value="sessionValue" scope="session" />
<c:set var="requestKey" value="requestValue" scope="request" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSTL</title>
</head>
<body>
<c:set var="inputValue" value="${param['inputKey']}" />
<form action="" method="POST">param<input name="inputKey"
value='<c:out value="${inputValue}" />' /><input type="submit" />
</form>
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<th colspan="2">Application Scope</th>
</tr>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<c:forEach var="entry" items="${applicationScope}">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:out value="${entry.value}" /></td>
</tr>
</c:forEach>
</table>
<br />
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<th colspan="2">Session Scope</th>
</tr>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<c:forEach var="entry" items="${sessionScope}">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:out value="${entry.value}" /></td>
</tr>
</c:forEach>
</table>
<br />
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<th colspan="2">Request Scope</th>
</tr>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<c:forEach var="entry" items="${requestScope}">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:out value="${entry.value}" /></td>
</tr>
</c:forEach>
</table>
<br />
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<th colspan="2">Page Scope</th>
</tr>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<c:forEach var="entry" items="${pageScope}">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:out value="${entry.value}" /></td>
</tr>
</c:forEach>
</table>
<br />
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<th colspan="2">Header Values</th>
</tr>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<c:forEach var="entry" items="${headerValues}">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:forEach var="aValue" items="${entry.value}">
<c:out value="${aValue}" />
<br />
</c:forEach></td>
</tr>
</c:forEach>
</table>
<br />
<table border="1" cellpadding="0" cellspacing="0" frame="box">
<tr>
<th colspan="2">Param Values</th>
</tr>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
<c:forEach var="entry" items="${paramValues}">
<tr>
<td><c:out value="${entry.key}" /></td>
<td><c:forEach var="aValue" items="${entry.value}">
<c:out value="${aValue}" />
<br />
</c:forEach></td>
</tr>
</c:forEach>
</table>

</body>
</html>

沒有留言:

網誌存檔