JavaWeb测试题-JSTL+EL表达式
提醒:
使用JSTL需要导入支持JSTL的jar包
解析:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>
<%
List<Map<String,String>> list=new ArrayList<Map<String,String>>();
Map<String,String> clas=new HashMap<String,String>();
clas.put("classname", "rc191");
clas.put("number", "32");
Map<String,String> clas2=new HashMap<String,String>();
clas2.put("classname", "rc192");
clas2.put("number", "31");
list.add(clas);
list.add(clas2);
request.setAttribute("list", list);
%>
<br>
<c:forEach var="cla" items="${list }" varStatus="s">
${s.index+1}-${cla.classname }: ${cla.number }人<br>
</c:forEach>
</body>
</html>
运行截图:
解析:就是采用param去获取表单参数的值。
解析:
1.session设置界面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<!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>
<%
Map<String,String> ecmap=new HashMap<String,String>();
ecmap.put("ecname", "EDG");
ecmap.put("ectype", "world");
ecmap.put("result", "冠军");
session.setAttribute("ecmap", ecmap);
request.getRequestDispatcher("1.jsp").forward(request, response);
%>
</body>
</html>
2.跳转后的1.jsp页面
<%@ 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>
<br>
${sessionScope.ecmap.ecname }
<br>
${sessionScope.ecmap.result }
</body>
</html>
运行截图::
解析:
<%@ 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>
<%
request.setAttribute("testdata", "testdata11");
%>
${requestScope.testdata}
</body>
</html>
运行截图: