<c:set var="sessionCounter" scope="session"
value="${sessionCounter + 1}" />
第一次访问见面的时候不存在计数器,所以第一次会设置计数器为1(EL计算前缺省值为0)。session是针对一个用户,而application是可以多用户共享。
注意:request请求和jsp:forward配合使用。各项说明见上面一篇笔记。
<jsp:include page="included.jsp" flush="true">
<jsp:forward page= "nextpage.jsp"/>
前者页面不会转向include所指的页面,只是显示该页的结果,主页面还是原来的页面。执行完后还会回来,相当于函数调用。并且可以带参数.后者完全转向新页面,不会再回来
<jsp:forward>
重定向一个HTML文件,JSP文件,或者是一个程序段.
例子
1<jsp:forward page="/servlet/login" />
2<jsp:forward page="/servlet/login">
<jsp:param name="username" value="jsmith" />
</jsp:forward>
你能够向目标文件传送参数和值,如果你使用了<jsp:param>标签的话,目标文件必须是一个动态的文件,能够处理参数.
例题:
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Counter page</title>
</head>
<body bgcolor="white">
<%-- Increment counters --%>
<c:set var="sessionCounter" scope="session"
value="${sessionCounter + 1}" />
<c:set var="applCounter" scope="application"
value="${applCounter + 1}" />
<h1>Counter page</h1>
This page has been visited <b>${sessionCounter}</b> times
within the current session, and <b>${applCounter}</b> times
by all users since the application was started.
</body>
</html>
URL复写:
Cookie:服务器在一个应答首部传递给浏览器的名称/值对。浏览器保存的时间
<c:url value=”counter.jsp”>
ii) 还会对嵌套的<c:param>定义的查询参数进行URL编码。 <c:url>
书上例题:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Counter page</title>
</head>
<body bgcolor="white">
<%-- Increment the counter --%>
<c:set var="sessionCounter" scope="session"
value="${sessionCounter + 1}" />
<h1>Counter page</h1>
This page has been visited <b>${sessionCounter}</b> times
within the current session.
<p>
Click here to load the page through a
<a href="counter2.jsp">regular link</a>.
<p>
Click here to load the page through an
<a href="<c:url value="counter2.jsp" />">encoded link</a>.
</body>
</html>