<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSTL学习</title>
</head>
<body>
<%
out.println(" 标准标签库jstl");
session.setAttribute("name", "张三");
%>
<br><hr>
<%--
EL表达式
语法: ${表达式}
EL表达式隐式对象:
sessionScope <=>session对象
param <=>表单提交的参数 request.getParameter("name");
requestScope
--%>
<c:out value="标准标签库jstl"></c:out>
<c:out value="${sessionScope.name}"></c:out>
<c:out value="${sessionScope['name']}"></c:out>
<c:out value="aaa"></c:out>
<h1><c:out value="一、标签:out , EL隐式对象: sessionScope,requestScope"></c:out></h1>
<%
session.setAttribute("name1", "李四");
session.setAttribute("number2", "1002");
request.setAttribute("number", 1001);
%>
<c:out value = "${sessionScope.name1}"></c:out>
<c:out value = "${sessionScope.number2}"></c:out>
<c:out value = "${requestScope['number']}"></c:out>
<br><hr>
<h1><c:out value="二、标签:set , EL隐式对象: param "></c:out></h1>
<c:set var="age" value="23" scope="session"></c:set>
<c:out value="${age}" default="20"></c:out>
<form action="./index.jsp">
xx:<input type="text" name="num"/>
<input type="submit" value="提交"/>
<c:out value="获取param值加10 = ${param.num+10}"></c:out>
</form>
<br><hr>
<h1><c:out value="三、set标签给javaBean属性赋值"></c:out></h1>
<%-- jsp:userBean实例化Person类 --%>
<jsp:useBean id="person" class="cn.bean.Person" scope="page"></jsp:useBean>
<c:set target="${person}" property="name" value="小明"></c:set>
<c:out value="${person.name}"></c:out>
<br>
<jsp:setProperty property="name" name="person" value="麻子"></jsp:setProperty>
<jsp:getProperty property="name" name="person"></jsp:getProperty>
<br><hr>
<h1><c:out value="四、标签:remove catch"></c:out></h1>
<c:set var="firstName" value="李子"></c:set>
<c:set var="secondName" value="小李"></c:set>
<!--删除firstName属性 -->
<c:remove var="firstName"></c:remove>
<c:out value="${firstName}"></c:out>
<c:out value="${secondName}"></c:out>
</body>
</html>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSTL学习</title>
</head>
<body align="center">
<h1>if标签</h1>
<form action="./jsp_Jstl_two.jsp">
<input type="text" name="score"/>
<input type="submit" value="提交"/>
</form>
<c:if test="${param.score >=90}" var="result">
<c:out value="成绩..."></c:out>
</c:if>
<c:out value="${result}"></c:out>
<br><hr>
<h1>choose、when、otherwise学习</h1>
<c:catch var="error">
<c:choose>
<c:when test="${param.score<=100 && param.score>=95}">
<c:out value="非常优秀"></c:out>
</c:when>
<c:when test="${param.score<95 && param.score>=90}">
<c:out value="十分优秀"></c:out>
</c:when>
<c:when test="${param.score<90 && param.score>=80}">
<c:out value="优秀"></c:out>
</c:when>
<c:otherwise>
<c:out value="请检查您输入的值"></c:out>
</c:otherwise>
</c:choose>
</c:catch>
<c:out value="${error}"/>
<br><hr>
<h1>forEach学习</h1>
<%
ArrayList<String> lists = new ArrayList();
lists.add("one");
lists.add("two");
lists.add("three");
lists.add("four");
session.setAttribute("list", lists);
%>
<c:forEach items="${sessionScope.list}" var="item" begin="1" end="3">
<c:out value="${item}"/>
</c:forEach>
<br><hr>
<h1>forTokens学习</h1>
<c:import url="http://www.baidu.com" charEncoding="utf-8"></c:import>
<jsp:include page="./index.jsp"></jsp:include>
<br><hr>
<h1>redirect学习 重定向:转发</h1>
<%-- <c:redirect url="./index.jsp">
<c:param name="num" value="10"></c:param>
</c:redirect> --%>
<br><hr>
<h1>url</h1>
<c:url var="main" value="http://192.168.5.7:8080/Jstl/index.jsp">
<c:param name="num" value="11"></c:param>
<c:param name="passWord" value="123"></c:param>
</c:url>
<c:out value="${main}"></c:out>
<a href="${main}">首页</a>
</body>
</html>
package cn.bean;
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}