JSP标签库大全

待续

Core Tag Library

 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:set var="temp" value="hello world" scope="page"/>
  ${temp }
<c:remove var="temp"/>

<%
String[] ss={"one","two","three"};
pageContext.setAttribute("ss",ss);
%>
<c:forEach var="s" items="${pageScope.ss }">
	${s}<br/>
</c:forEach>

<%
String temp="hello";
pageContext.setAttribute("temp",temp);
%>
<c:if test="${!empty temp}">
	${temp }
</c:if>
<c:if test="${1==2 }">
  1==2
</c:if>

<%
String temp="two";
pageContext.setAttribute("temp",temp);
%>
<c:choose>
	<c:when test="${temp=='one' }">
		one
	</c:when>
	<c:when test="${temp=='two' }">
		two
	</c:when>
	<c:otherwise>
		otherwise
	</c:otherwise>
</c:choose>

<c:url var="hello"  value="/jsp/hello.jsp">
	<c:param name="username"> jiajia</c:param>
</c:url>
 <a href="${hello}"> hello world</a>

<c:import url="/jsp/hello.jsp">
	<c:param name="username" value="jiajia"></c:param>
</c:import>

XML Tag Library

<?xml version="1.0" encoding="UTF-8"?>
<books>
	<book id="1">
		<name>jia</name>
		<price>100</price>
	</book>
	<book id="2">
		<name>wodwl</name>
		<price>200</price>
	</book>
</books>
	<c:import url="/jsp/xmlTest.xml" var="xml" charEncoding="UTF-8"/></c:import>
	<x:parse doc="${xml}" var="booklist" scope="application"></x:parse>
	<x:forEach var="item" select="$booklist/books/book">
		<x:out select="$item/@id"/>
		<c:set var="name">
			<x:out select="$item/name"/>
		</c:set>
		<c:set var="price">
			<x:out select="$item/price"/>
		</c:set>
		<c:url var="url" value="/jsp/hello.jsp">
			<c:param name="name">${name}</c:param>
			<c:param name="price">${price}</c:param>
		</c:url>
		<a href="${url}">
			<x:out select="$item/name"/>
		</a>
	</x:forEach>

注意:以下不加上charEncoding='utf-8"可能导致乱码
<c:import url="/jsp/xmlTest.xml" var="xml" charEncoding="UTF-8"/></c:import>
 
 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值