<%@page import="java.util.LinkedList"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ 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>
<%
String user = request.getParameter("user");
LinkedList<String> stuList = new LinkedList<String>();
stuList.add("小明");
stuList.add("小强");
stuList.add("小账");
int[] score = { 99, 98, 97, 96, 95 };
request.setAttribute("sco", score);
request.setAttribute("stu", stuList);
request.setAttribute("user", user);
%>
<form action="jstl.jsp" method="post">
<input type="text" name="user"> <input type="submit"
value="提交">
</form>
<%
if (request.getParameter("user").equals("admin")) {
%>
${user}
<%
}
%>
<c:if test="${user == 'teacher' }">
${user },你好!!
</c:if>
<c:choose>
<c:when test="${user == 'teacher' }">
下面是你的学生信息:<br />
<c:forEach items="${stu}" var="st">
${st}
</c:forEach>
</c:when>
<c:when test="${user == 'student' }">
下面是你的成绩信息:<br />
<c:forEach items="${sco}" var="st" step="2">
${st}
</c:forEach>
</c:when>
<c:otherwise>
对不起,没有你要的信息:<br />
</c:otherwise>
</c:choose>
</body>
</html>
jstl用法
最新推荐文章于 2022-08-19 22:55:25 发布