jsp表单中request.getParameter获取文本框/编辑框/隐藏域的值实例源码



jsp中request.getParameter获取文本框/编辑框/隐藏域的值实例源码。

jsp提交页面源码:

<%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”" %>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>文本框提交页面</title>
<link href=”css/style.css” type=”text/css” rel=”stylesheet”>
</head>
<script language=”javascript” type=”">
function checkEmpty(form){
for(i=0;i<form.length;i++){
if(form.elements[i].value==”"){
alert(“表单的值不能为空”);
return false;
}
}
}
</script>
<body><div align=”center”>
<font color=”#FFFFFF”>填写文本框/编辑框/隐藏域的值</font>
<form name=”form” method=”post” action=”dealwith.jsp” onSubmit=”return checkEmpty(form)”>
<table width=”352″ border=”0″>
<tr>
<td width=”110″ height=”20″><font color=”#FFFFFF”>填写文本框内容:</font></td>
<td width=”226″><input name=”textOne” type=”text”></td>
</tr>
<tr>
<td height=”119″><font color=”#FFFFFF”>填写编辑框内容:</font></td>
<td><textarea name=”textwo” cols=”30″ rows=”8″ ></textarea></td>
</tr>
<tr>
<td height=”26″><font color=”#FFFFFF”>隐藏域的值为:</font></td>
<td><font color=”#FFFFFF”>男</font>
<input name=”textThree” type=”hidden” value=”男”></td>
</tr>
</table>
<input type=”submit” name=”Submit” value=”提交”>
</form>
</div>
</body>
</html>

接收表单信息页面,jsp源码实例:

<%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”" %>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″>
<title>获取文本框/编辑框/隐藏域的值</title>
<link href=”css/style.css” type=”text/css” rel=”stylesheet”>
</head>
<%request.setCharacterEncoding(“gb2312″);%>
<body background=”beijing.jpg”><div align=”center”>
<font color=”#FFFFFF”>获取文本框/编辑框/隐藏域的值</font>

<table width=”352″ border=”0″>
<tr>
<td width=”110″ height=”20″><font color=”#FFFFFF”>获取文本框内容:</font></td>
<td width=”226″><font color=”#FFFFFF”><%=request.getParameter(“textOne”)%></font></td>
</tr>
<tr>
<td height=”119″><font color=”#FFFFFF”>获取编辑框内容:</font></td>
<td><font color=”#FFFFFF”><%=request.getParameter(“textwo”)%></font></td>
</tr>
<tr>
<td height=”26″><font color=”#FFFFFF”>获取隐藏域的值为:</font></td>
<td><font color=”#FFFFFF”><%=request.getParameter(“textThree”)%></font></td>
</tr>
</table>

<a href=”index.jsp”><font color=”#FFFFFF”>返回</font></a></div>
</body>
</html>