jstl标签

Posted haiziguo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jstl标签相关的知识,希望对你有一定的参考价值。

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>jstl练习</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

</head>

<body>
    This is my JSP page.
    <br>
    <h6>下面是out测试</h6>
    <c:out value="out"></c:out>
    <h6>下面是set测试</h6>
    <%
        request.setAttribute("out", "hello");
    %>
    <c:set var="username" value="test"></c:set>
    <c:out value="${username }" />
    <h6>下面是curl测试</h6>
    <a
        href="<c:url value=‘index.jsp‘>
      <c:param name=‘username‘ value=‘战三‘/> </c:url>">index
    </a>

    <h6>下面是if测试</h6>
    <c:set var="password" value="12345"></c:set>
    <c:if test="${not empty password}">
        <c:out value="${password}"></c:out>
    </c:if>

    <h6>下面是choose测试</h6>
    <c:choose>
        <c:when test="${not empty param.name}">测试空</c:when>
        <c:otherwise>不为空</c:otherwise>
    </c:choose>
    <h6>下面是foreach测试</h6>
    <c:forEach var="i" begin="1" end="10">
        ${i}
    </c:forEach>
    <br />
    <%
        String[] array = { "1", "2" };
        request.setAttribute("array", array);
    %>

    <c:forEach items="${array}" var="item">
         ${item}
    </c:forEach>

<h6>下面是fmt测试</h6>
 
<c:out value="记得加fmt库"/>
<%
    Date date=new Date();
    request.setAttribute("date", date);
 %>
 当前时间为:
<fmt:formatDate value="${date}" pattern="yyyy-MM-dd hh:mm:ss"/>
</body>
</html>

 

以上是关于jstl标签的主要内容,如果未能解决你的问题,请参考以下文章

JSTL

复习整理1:jsp标准标签库jstl

jsp之jstl核心标签库

JSTL标签库

什么是Taglib?

JSP常用标签——JSTL标签和EL表达式