EL-JSTL

EL-JSTL

EL-JSTLEL-JSTL

EL-JSTLEL-JSTL

EL-JSTL

 

EL-JSTLEL-JSTLEL-JSTLEL-JSTL

JAVAWEB开发包的下载百度云链接:https://pan.baidu.com/s/15mkgNcEBXsZ-D30s9RKL8A

 

EL相关代码操作:

 

<%@page import="java.util.ArrayList"%>

<%@page import="java.util.List"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!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>

<%

      pageContext.setAttribute("msg","pageContext");

      session.setAttribute("msg","session");

      request.setAttribute("msg","request");

      application.setAttribute("msg","application");

%>

pageContext:${pageScope.msg}<br/>

session:${sessionScope.msg}<br/>

request:${requestScope.msg}<br/>

application:${applicationScope.msg}<br/>

<%

   List list=new ArrayList();

   request.setAttribute("list",list);   //必须放到作用域里面获取

  

%>

获取上下文路径

${empty list}

${pageContext.request.contextPath}

${pageContext.getRequest().getContextPath()}

</body>

</html>

jstl相关标签库查找大全:参考手册链接:https://pan.baidu.com/s/17UT9G0hNL6ooFLK3V--zVA

EL-JSTL

EL-JSTL

EL-JSTL

相关代码操作:

<%@page import="java.util.Arrays"%>

<%@page import="java.util.ArrayList"%>

<%@page import="java.util.List"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

    <%@taglib uri="http://java.sun.com/jsp/jstl/core" 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>

    <%

        Integer age=18;

        request.setAttribute("age", age);

    %>

    <c:if test="${age>18 }" var="ret" scope="page"></c:if>

    判断的结果为 ${ret}

    <hr/>

    <c:choose>

       <c:when test="${age>60 }">

       您太老了,我怕你承受不住

       </c:when>

        <c:when test="${age<18 }">

       您太嫩了,我不想让你受到伤害

       </c:when>

       <c:otherwise>

      你们刚好,接我一招

       </c:otherwise>

    </c:choose>

    <hr/>

    <%

         List<String> stu=Arrays.asList(new String[]{"zhouzhou","xinxin","chichi"});

         request.setAttribute("stu", stu);

    %>

    <c:forEach items="${stu}" var="item" varStatus="vs">

       ${vs.count}----->${pageScope.item}<br>

    </c:forEach>

    <c:forEach var="num" begin="1" end="10" step="1">

       ${pageScope.num}<br>

    </c:forEach>

</body>

</html>

 

EL-JSTL

<%@page import="java.util.Date"%>

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

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

<!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>

<fmt:setBundle basename="app"/>

<form action="">

     <fmt:message key="username"/><input type="text" name="username" /><br>

     <fmt:message key="password"/><input type="password" name="password" /><br>

     <input type="submit" name="username" />

</form>

<hr/>

<%

      Date date=new Date();

      request.setAttribute("date", date);

%>

当地时间:<fmt:formatDate value="${ date}" pattern="yyyy-MM-dd HH:mm:ss SS"/>

</body>

</html>