【JSP】JSTL使用core标签总结(不断更新中)
使用core标签
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
接着可以在页面上使用,如core标签:
<c:out value=“${expression}” default=“a”/>
<c:set var=“str” value=“试下” scope=“session”></c:set>//设置某个范围如session属性的值
<c:set target=“bean实例” property=“” value=“”/>//设置某个bean成员变量的值 等同于 <jsp:setProperty property=“” value=“”/>
<c:remove var=“” scope=“”/>//移除某个范围的变量
要运行JSTL标签,需要jstl1.2.jar包
core标签库
JSTL核心标签库支持使用<c:import>来包含文件,使用<c:url>来打印和格式化URL,使用<c:redirect>来重定向URL.
将url http://www.url.com/edit.js包含到当前页的当前位置,并将url保存到newsfeed变量中.
<c:import url="http://www.url.com/edit.js" var="newsfeed"/>
将请求重新定向到http://www.yourname.com/login.jsp页,相当于response.setRedirect();
<c:redirect url="http://www.yourname.com/login.jsp"/>
<c:param>标签
<c:redirect url="login.jsp"><c:param name="id" value="888"/></c:redirect>
将参数888以id为名字传递到login.jsp页面,相当于login.jsp?id=888
If判断
<%
int score = 90;
pageContext.setAttribute("score", score);
%>
<c:if test="${score>80}">优秀</c:if>
if多分支判断
<%
int score = 90;
pageContext.setAttribute("score", score);
%>
<c:choose>
<c:when test="${score<60}">不及格</c:when>
<c:when test="${score<80}">及格</c:when>
<c:otherwise>优秀</c:otherwise>
</c:choose>
for循环遍历ArrayList
<%
ArrayList aList = new ArrayList();
aList.add(23);
aList.add(true);
aList.add("ArrayList");
aList.add(new Date());
aList.add(3445652);
pageContext.setAttribute("aList", aList);
int size = aList.size();
pageContext.setAttribute("size", size);
%>
<c:forEach begin="0" end="${size}" var="i">
${aList[i]}
</c:forEach>
增强型for循环遍历ArrayList
<%
ArrayList aList = new ArrayList();
aList.add(23);
aList.add(true);
aList.add("ArrayList");
aList.add(new Date());
aList.add(3445652);
pageContext.setAttribute("aList", aList);
%>
<c:forEach items="${aList}" var="i">
${i}
</c:forEach>
【JSP】JSTL使用core标签总结(不断更新中)的更多相关文章
- jsp标签精华(持续更新中)
<%@ taglib uri="/struts-tags" prefix="s" %> <%@ taglib uri="http:/ ...
- jsp if else c标签 总结
JSTL标签使用方法 keyword:JSTL标签.<c:choose>.<c:forEach>.<c:forTokens>.<c:if>.<c: ...
- day13(JSTL和自定义标签&MVC模型&javaweb三层框架)
day13 JSTL标签库(重点) 自定义标签(理解) MVC设计模式(重点中的重点) Java三层框架(重点中的重点) JSTL标签库 1 什么是JSTL JSTL是apache对EL表达式的扩 ...
- JSTL标签急速秒杀jsp页面中的java代码(一)---Core标签库
JSTL标签简介 ===================================================================== JSTL的全称是JavaServer Pa ...
- JSP第五篇【JSTL的介绍、core标签库、fn方法库、fmt标签库】
什么是JSTL JSTL全称为 JSP Standard Tag Library 即JSP标准标签库. JSTL作为最基本的标签库,提供了一系列的JSP标签,实现了基本的功能:集合的遍历.数据的输出. ...
- jsp不解析el表达式,不识别jstl标签,找不到http://java.sun.com/jsp/jstl/core
问题描述: jsp页面中el表达式,例如:${pageContext.request.contextPath},原样呈现,未被解析. 解决方案: 为jsp页添加page指令如下: <%@ pag ...
- 使用jstl标签时提示The absolute uri: http://java.sun.com/jsp/jstl/core cannot
http://www.360doc.com/content/11/1219/15/1007797_173395882.shtml 检查应用目录下WEB-INF的lib里是否有jstl.jar和stan ...
- struts标签错误:Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core"
今天使用eclipse开发ssh,出现Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/co ...
- 【JSP jstl c标签】使用c:foreach 报错(警告)”test does not support runtime expressions“
后台封装的数据是个list,传递给前台,显示如下: <c:forEach items="${userInfo}" var="user"> 用户Nam ...
随机推荐
- 类 .xml
pre{ line-height:1; color:#1e1e1e; background-color:#d2d2d2; font-size:16px;}.sysFunc{color:#627cf6; ...
- redhat Enterprise Linux Server release 7.2(Maipo) 安装redis-stat
项目需要在rh7.2安装redis-stat,各种编译不过.通过一步步跟踪编译错误日志发现时缺少各种开发库. 需要安装的库列表如下: zlib-devel openssl-devel readline ...
- 比赛组队问题 --- 递归解法 --- java代码 --- 八皇后问题
两队比赛,甲队为A.B.C3人,乙队为X.Y.Z3人.已知A不和X比,C不和X.Z比,请编程序找出3队赛手名单 采用了与八皇后问题相似的解法,代码如下: 如有疑问请链接八皇后问题的解法:http:// ...
- C字符串和C++中string的区别 &&&&C++中int型与string型互相转换
在C++中则把字符串封装成了一种数据类型string,可以直接声明变量并进行赋值等字符串操作.以下是C字符串和C++中string的区别: C字符串 string对象(C++) 所需的头文件名称 ...
- How To Set Up Port Forwarding in Linux
Port forwarding usually used when we want our computer act like a router. Our computer receive the p ...
- Ubuntu安装PostgreSQl
warrior@pc:~$ sudo apt-get install postgresql-xx-xx #可以使用Tab键进行代码补全 warrior@pc:~$ sudo su postgres # ...
- ubuntu下设置开机自动挂载硬盘
我们在linux中常常用mount命令把硬盘分区或者光盘挂载到文件系统中./etc/fstab就是在开机引导的时候自动挂载到linux的文件系统. 如果给计算机配了一块新磁盘,已经分区,格式化,挂载, ...
- 【转】B树、B-树、B+树、B*树
B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right): 2.所有结点存储一个关键字: 3.非叶子结点的左指针指向小于其关键字的子树,右指针指向大于其关键字的子树: 如: B ...
- [iOS微博项目 - 3.4] - 获取用户信息
github: https://github.com/hellovoidworld/HVWWeibo A.获取用户信息 1.需求 获取用户信息并储存 把用户昵称显示在“首页”界面导航栏的标题上 ...
- LeetCode7:Reverse Integer
Reverse digits of an integer. Example1: x = 123, return 321Example2: x = -123, return -321 click to ...