日期:2014-05-16 浏览次数:20548 次
要求:使用jsp+servlet完成一个表单验证,通过表单提交信息给Servlet,Servlet获取到信息后,处理,把信息放到request对象中,如果用户提交的姓名为空,不能跳转,否则,将信息全部显示出来。
<%@ 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 'index2.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 bgcolor="#7FFFD4">
<center>
<h3>
表单提交
</h3>
<form action="servlet/TableSubmitServlet" method="post">
<table border="2px" width="260" height="192">
<tr>
<td>
username
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
sex
</td>
<td>
<input type="radio" name="sex" value="boy" />
boy
<input type="radio" name="sex" value="girl" />
girl
</td>
</tr>
<tr>
<td>
address
</td>
<td>
<input type="text" name="address" />
</td>
</tr>
<tr>
<td>
likes
</td>
<td>
<input type="checkbox" name="likes" value="sing" />
sing
&n