out.jsp
代码:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
<html>
<head>
<title>page</title>
</head> <body>
<c:out value="欢迎访问" /><br>
<c:out value="${session.username}" default="anonymous" /><br>
<c:out value="${username}" default="anonymous" /><br>
<!--escapeXml 是转义,如果值是false,则不需要转义,否则需要转义-->
<c:out value="<h1>欢迎访问</h1>" escapeXml="false" />
<c:out value="<h1>欢迎访问</h1>" /><br>
</body>
</html>
----------------------------------------------------------------------------------------
set.jsp
代码:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
<html>
<head>
<title>page</title>
</head>
<body>
<c:set var="username" value="SunWukong" scope="session" />
<c:set var="username" scope="session">
SunWukong
</c:set>
</body>
</html>
----------------------------------------------------------------------------------------
remove.jsp
代码:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
<html>
<head>
<title>page</title>
</head>
<body>
<c:remove var="username" scope="session"/>
</body>
</html>
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
catch.jsp
代码:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
<html>
<head>
<title>page</title>
</head>
<body>
<c:catch var="ex">
<%
String number = "none";
int i = Integer.parseInt(number);
%>
</c:catch>
${ex} </body>
</html>
----------------------------------------------------------------------------------------
if.jsp
代码:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
<html>
<head>
<title>page</title>
</head>
<body>
<c:if test="${session.username=='system'}">
欢迎系统管理员!
</c:if> </body>
</html>
----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
forEach.jsp
代码:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core " prefix="c"%>
<html>
<head>
<title>page</title>
</head>
<body>
<%
String names[] = new String[4];
names[0] = "孙悟空";
names[1] = "猪八戒";
names[2] = "沙僧";
names[3] = "唐僧";
pageContext.setAttribute("names", names);
%>
<c:forEach items="${names}" var="name">
${name}<br>
</c:forEach>
<c:forEach items="${names}" var="name" begin="0" end="3" step="1">
${name}<br>
</c:forEach> <c:forEach items="${names}" var="name" varStatus="i">
${name}<br>
index: ${i.index}<br>
count: ${i.count}<br>
first: ${i.first}<br>
last: ${i.last}<br>
</c:forEach>
</body>
</html>
标签:--------------------------------------------------------------------------------
From: https://blog.51cto.com/u_16034393/6153309