生活随笔
收集整理的這篇文章主要介紹了
JSP 第一天:提交表单--获取表单中的数据值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
主要用到兩個內置的對象:out? 和 request
out:用來在小腳本里面輸出顯示內容
request:用來獲取用戶提交的信息(包括:用戶的IP,表單中的內容等)
[java]?view plaincopyprint?
<%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%>?? <%?? String?path?=?request.getContextPath();?? String?basePath?=?request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";?? %>?? ?? <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">?? <html>?? ??<head>?? ????<base?href="<%=basePath%>">?? ?????? ????<title>My?JSP?'index.jsp'?starting?page</title>?? ????<meta?http-equiv="pragma"?content="no-cache">?? ????<meta?http-equiv="cache-control"?content="no-cache">?? ????<meta?http-equiv="expires"?content="0">?????? ????<meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3">?? ????<meta?http-equiv="description"?content="This?is?my?page">?? ????<!--?? ????<link?rel="stylesheet"?type="text/css"?href="styles.css">?? ????-->?? ?????? ??</head>?? ???? ??<body>?? ????<form?action="getInfo.jsp"?name="myform"?method="post">?? ????????<table>?? ????????????<tr>?? ????????????????<td>姓名:</td>?? ????????????????<td><input?type?="text"?name="txtname"??/></td>?? ????????????</tr>?? ????????????<tr>?? ????????????????<td>密碼:</td>?? ????????????????<td><input?type?="password"?name="txtpwd"??/></td>?? ????????????</tr>?? ????????????<tr>?? ????????????????<td>男<input?type="radio"?name="sex"?value="male"?/></td>?? ????????????????<td>女<input?type="radio"?name="sex"?value="female"?/></td>?? ????????????</tr>?? ????????????<tr>?? ????????????????<td?colspan="4">?? ????????????????籃球<input?type="checkbox"?name="hobby"?value="籃球"?/>?? ????????????????排球<input?type="checkbox"?name="hobby"?value="排球"?/>?? ????????????????足球<input?type="checkbox"?name="hobby"?value="足球"?/>?? ????????????????乒乓球<input?type="checkbox"?name="hobby"?value?=?"乒乓球"/>?? ????????????????</td>?? ????????????</tr>?? ????????????<tr>?? ????????????????<td?colspan="2">?? ????????????????????<input?type="submit"?name="submit"?value="提交"?/>?? ????????????????????<input?type="reset"?name="reset"?value="重置"?/>?? ????????????????</td>?? ????????????</tr>?? ????????</table>?? ????</form>?? ??</body>?? </html>??
?
[java]?view plaincopyprint?
<%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%>?? <%?? String?path?=?request.getContextPath();?? String?basePath?=?request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";?? %>?? ?? <!DOCTYPE?HTML?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN">?? <html>?? ??<head>?? ????<base?href="<%=basePath%>">?? ?????? ????<title>My?JSP?'getInfo.jsp'?starting?page</title>?? ?????? ????<meta?http-equiv="pragma"?content="no-cache">?? ????<meta?http-equiv="cache-control"?content="no-cache">?? ????<meta?http-equiv="expires"?content="0">?????? ????<meta?http-equiv="keywords"?content="keyword1,keyword2,keyword3">?? ????<meta?http-equiv="description"?content="This?is?my?page">?? ????<!--?? ????<link?rel="stylesheet"?type="text/css"?href="styles.css">?? ????-->?? ?? ??</head>?? ???? ??<body>?? ????<%?? ????????request.setCharacterEncoding("UTF-8");?? ?????????? ????????String?name=request.getParameter("txtname");?? ????????String?pwd=request.getParameter("txtpwd");?? ????????String?sex=request.getParameter("sex");?? ????????String[]?hobby=request.getParameterValues("hobby");?? ?????%>?? ?????姓名:<%=name?%><br?/>?? ?????密碼:<%=pwd?%><br?/>?? ?????性別:<%=sex?%><br?/>?? ?????愛好:<%?? ????????for(String?h?:?hobby){?? ????????????out.print(h);?? ????????}?? ??????%><br?/>?? ??</body>?? </html> ?
總結
以上是生活随笔為你收集整理的JSP 第一天:提交表单--获取表单中的数据值的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。