JSTL基本用法。

来源:互联网 发布:linux make 编辑:程序博客网 时间:2024/06/02 03:16

1.JSTL : javaserverpages standard tag library  JSP标准标签库

2.目的:用这些标签取代JSP页面上的JAVA代码
3.引入jsp,<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

4<c:set var="ctxPath" value="${pageContext.request.contextPath}" scope="request" />

   ///var是变量名,value是值,scope是使用范围

5 <c:set var="number" [scope="{page|request|session|application}"]>2</c:set> 
6 <c:set value="wzk" target="Userbean" propertyName="name"/>
   ///针对JAVABEAN进行操作,target是对应的JAVABEAN名 
7 <c:set target="Userbean" propertyName="name">"wzk"</c:set>
[注:] 默认范围都是page

8.

c:choose 没有具体的作用,它只是后面两个的父标签,这里把三者一起介绍
     <c:set var="IDE" value="Eclipse"/>
     <c:choose>
         <c:when test="${IDE=='JBuilder'}">
             <c:out value="你使用的开发工具为JBuilder"/>
         </c:when>
         <c:when test="${IDE=='Eclipse'}">
             <c:out value="你使用的开发工具为Eclipse"/>
         </c:when>
         <c:when test="${IDE=='JCreator'}">
             <c:out value="你使用的开发工具为JCreator"/>
         </c:when>
         <c:otherwise>
              <c:out value="你是高手!用记事本写代码?"/>
         </c:otherwise>
     </c:choose> 
[注:]   <c:otherwise>的个数是<=1个




原创粉丝点击