jstl

导入

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<body>
    <c:out  value="This is my test tag"/>

</body>

 具体使用:

<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <c:set value="amaker" var="name" scope="request"/>
    <c:out value="${name }"/>
    <hr>
    <!-- 使用javabean -->
    <jsp:useBean id="per" class="bean.Person"/>
    <c:set target="${per }" property="name" value="tom"/>
    <c:set target="${per }" property="age"    value="20"/>
    <c:out value="${per.name }"/>
    <c:out value="${per.age }"/>
    
    <c:if test="${per.age<30 }">
        年龄太小,拒绝访问
    </c:if>
    <hr>
    
    <c:set value="admin" var="username" scope="session"/>
    <c:if test="${username=='admin' }">
        <input type="button" value="Delete"/>
    </c:if> 
    <c:if test="${username!='admin' }">
        <input type="button" value="Delete" disabled="disabled"/>
    </c:if> 
    
    <hr>
    <c:set var="score" value="90" scope="request"/>
    <c:choose>
        <c:when test="${score>=90 }">优秀</c:when>
        <c:when test="${score<90 }">良好</c:when>
    </c:choose>
    <hr>
    <c:forEach var="i" begin="1" end="5">
        <c:out value="${i }"/>    
    </c:forEach>
    <hr>
    <%
        ArrayList list = new ArrayList();
        list.add("a");
        list.add("b");
        request.setAttribute("List", list);
    %>
    
    <c:forEach var="i" items="${List }">
        <c:out value="${i }"/>
    </c:forEach>
</body>
</html>

 

posted @ 2016-08-19 17:16  式微胡不归  阅读(192)  评论(0编辑  收藏  举报