1.使用EL创建一个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 >
${pageContext.request.contextPath }
<form action ="${pageContext.request.contextPath }/9.jsp" method ="post" >
用户名:<input type ="text" name ="username" > <br />
密 码:<input type ="text" name ="password" > <br />
<input type ="checkbox" name ="hobby" value ="唱歌" > 唱歌<br />
<input type ="checkbox" name ="hobby" value ="篮球" > 篮球<br />
<input type ="submit" value ="提交" >
</form >
</body >
</html >
2.获取表单信息
<%@ 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 >
<%
response .setContentType("text/html;charset=UTF-8" );
request .setCharacterEncoding("UTF-8" );
%>
${param.username }
${paramValues.hobby[0] }<br />
${header["User-Agent"]} }<br />
${cookie.JSESSIONID.value }<br />
${cookie.JSESSIONID }<br />
</body >
</html >
1.JSTL
1. JSTL表达式需要导包jstl-1.2 .jar
2. JSTL表达式 实际上就是处理jsp页面的时逻辑处理
3. 通用标签 set out remove
4. 声明一个变量 默认是放在page域中
<%@ 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 >
<c:set var ="num" value ="10" scope ="session" > </c:set >
<c:out value ="${num1 }" default ="aaaa" > </c:out > <br />
${num }<br />
<c:remove var ="num" scope ="session" />
${num }<br />
</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 >
<c:set var = "n " value ="10" > </c:set >
<c:if test ="${3 < 5 }" > aaaa</c:if >
<c:if test ="${3 > 5 }" > bbbb</c:if >
<c:choose >
<c:when test ="${n==5 }" > 5</c:when >
<c:when test ="${n==10 }" > 10</c:when >
<c:otherwise >
xxxx
</c:otherwise >
</c:choose >
</body >
</html >
<%@page import="java.util.ArrayList" %>
<%@ 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 >
<%
ArrayList<String > list= new ArrayList();
list.add("aaaaa" );
list.add("bbbbb" );
list.add("ccccc" );
request .setAttribute("list" , list);
%>
<c:forEach items ="${list}" val ="l" >
${l }<br >
</c:forEach >
<c:forEach var ="i" begin ="0" end ="10" step ="2" >
<%-- ${list[i] }<br/> --%>
${i }<br />
</c:forEach >
</body >
</html >
<%@page import="java.util.ArrayList" %>
<%@ 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 >
<%
ArrayList<String > list= new ArrayList();
list.add("aaaaa" );
list.add("bbbbb" );
list.add("ccccc" );
list.add("dddd" );
list.add("eeee" );
request .setAttribute("list" , list);
%>
<table border ="1" >
<tr >
<th > 值</th >
<th > 索引</th >
<th > 计数</th >
<th > 第一个</th >
<th > 最后一个</th >
</tr >
<c:forEach items ="${list }" var ="l" varStatus ="vs" >
<tr >
<th > ${l }</th >
<th > ${vs.index }</th >
<th > ${vs.count }</th >
<th > ${vs.first }</th >
<th > ${vs.last }</th >
</tr >
</c:forEach >
</table >
</body >
</html >