jsp表单处理
一:通过参数名称获取表单数据的值
test_01.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <body> <form action="test_01.jsp" method="POST"> <input type="checkbox" name="a">a</input> <input type="checkbox" name="b">b</input> <input type="checkbox" name="c">c</input> <input type="submit" name="提交"></input> </form> </body> </html>
test_01.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>first</title> </head> <body> <table width="100%" border="1" align="center"> <tr bgcolor="#949494"> <th>parameter</th><th>value</th> </tr> <% String a=request.getParameter("a"); %> <tr><td>a</td><td> <%=a%> </td></tr> <% String b=request.getParameter("b"); %> <tr><td>b</td><td> <%=b%> </td></tr> <% String c=request.getParameter("c"); %> <tr><td>c</td><td> <%=c%> </td></tr> </table> </body> </html>
二:死循环获取下一个参数再获取值
test_02.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> New Document </title> <meta name="Generator" content="EditPlus"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> </head> <body> <form action="test_02.jsp" method="POST"> <input type="checkbox" name="a">a</input> <input type="checkbox" name="b">b</input> <input type="checkbox" name="c">c</input> <input type="submit" name="submit"></input> </form> </body> </html>
test_02.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pa
jsp的重定向
<% response.sendRedirect("http://www.baidu.com"); %> • 1 • 2 • 3
jsp统计页面的点击量
<% Integer hitsCount=(Integer)application.getAttribute("hitCounter"); if(hitsCount==null||hitsCount==0){ out.print("<h4>欢迎首次光临</h4>"); hitsCount=1; }else{ out.print("<h4>欢迎再次光临</h4>"); hitsCount++; } application.setAttribute("hitCounter",hitsCount); %>
jsp自动刷新
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.io.*,java.util.*" %> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>实现页面的3秒刷新</title> </head> <body> <% //设置3秒刷新一次 response.setIntHeader("Refresh",3); //获取当前的时间 Calendar canlendar=new GregorianCalendar(); String am_pm; int hour=canlendar.get(Calendar.HOUR); int minute=canlendar.get(Calendar.MINUTE); int second=canlendar.get(Calendar.SECOND); if(canlendar.get(Calendar.AM_PM)==0){ am_pm="AM"; }else{ am_pm="PM"; } String CT=hour+":"+minute+":"+second; out.println("当前时间为: " + CT + "\n"); %> </body> </html>
jsp的标准标签库(jstl)
根据jstl标签所提供的功能,可以分为5个类别
核心标签,格式化标签,sql标签,xml标签,jstl函数.