- <%@ page language="java" contentType="text/html;charset=UTF-8" %>
- <%@ taglib uri="/web-INF/tld/c-rt.tld" prefix="c-rt" %>
- <html>
- <head>
- <title>Java Code Geeks Snippets - Set Scoped Variables with JSTL in JSP Page</title>
- </head>
- <body>
- <%-- Set scoped variables --%>
- <c-rt:set var="var1" value="value1" scope="page" />
- <c-rt:set var="var2" value="value2" scope="request" />
- <c-rt:set var="var3" value="value3" scope="session" />
- <c-rt:set var="var4" value="value4" scope="application" />
- <%-- Print the values --%>
- var1: <c-rt:out value='${pageScope.var1}' />
- var2: <c-rt:out value='${requestScope.var2}' />
- var3: <c-rt:out value='${sessionScope.var3}' />
- var4: <c-rt:out value='${applicationScope.var4}' />
- <c-rt:set var="color" value="#dddddd" />
- color: <c-rt:out value='${color}' />
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/030620133735.html
来源: http://www.codesnippet.cn/detail/030620133735.html