简单的一个页面注册提交小例子,分为两个页面
Login.jsp
以及Login_Success.jsp
LOGIN.JSP
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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>学员注册页面</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">
-->
<script type="text/javascript">
function formSubmit()
{
var theForm;
theForm = document.stuForm;
if(theForm.stuNo.value==""){
alert("请输入学员编号!");
theForm.stuNo.focus();
return false;
}
if(theForm.stuName.value==""){
alert("请输入学员姓名!");
theForm.stuName.focus();
return false;
}
if(theForm.stuPass.value==""){
alert("请输入密码!");
theForm.stuPass.focus();
return false;
}
if(theForm.stuRpass.value==""){
alert("请输入确认密码!");
theForm.stuRpass.focus();
return false;
}
if(theForm.stuPass.value != theForm.stuRpass.value){
alert("两次密码输入不一致!");
theForm.stuPass.focus();
return false;
}
theForm.submit();
}
</script>
</head>
<body>
<center>
<h1>学员注册页面</h1>
<form name="stuForm" action="Login_Success.jsp" method="post">
<table>
<tr>
<td><b>学员编号:</b></td>
<td><input type="text" name="stuNo"></td>
</tr>
<tr>
<td><b>姓名:</b></td>
<td><input type="text" name="stuName"></td>
</tr>
<tr>
<td><b>登录密码:</b></td>
<td><input type="password" name="stuPass"></td>
</tr>
<tr>
<td><b>重复密码:</b></td>
<td><input type="password" name="stuRpass"></td>
</tr>
<tr>
<td><b>性别:</b></td>
<td><input type="radio" value="男" name="sex" checked> 男
<input type="radio" value="女" name="sex" > 女
</td>
</tr>
<tr>
<td><b>出生日期:</b></td>
<td>
<select name="birthDate">
<option value="1988" checked>1988</option>
<option value="1989">1989</option>
<option value="1990">1990</option>
<option value="1991">1991</option>
</select>
</td>
</tr>
</table>
<input type="button" value="提交" name="submit1" οnclick="formSubmit()">
</form>
</center>
</body>
</html>
Login_Success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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 'MyJsp.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>
<!--对提交到该JSP页面含有中文的信息实现以中文正常显示-->
<%request.setCharacterEncoding("GBK");%>
<center>
<h1>注册成功</h1>
<table>
<tr>
<td>学员编号:</td>
<td><%=request.getParameter("stuNo")%></td>
</tr>
<tr>
<td>学员姓名:</td>
<td><%=request.getParameter("stuName")%></td>
</tr>
<tr>
<td>性别:</td>
<td><%=request.getParameter("sex")%></td>
</tr>
<tr>
<td>出生日期:</td>
<td><%=request.getParameter("birthDate")%></td>
</tr>
</table>
</center>
</body>
</html>