java web简单的回显技术
回显技术简单的说就是在数据提交出现错误的时候, 已填写的信息仍在文本框中, 比如用户登录, 当用户输入错误的密码之后, 用户名仍在文本框, 只是密码框清空。
对于一些要填写很多信息的表单, 如果因为一些错误导致已经填写的整个表单信息重新填写, 对于用户非常地不友好。因此,回显就显得尤为重要了。
在此我编写了一个简单的注册请求程序,通过对用户名的判断来选择是否回显。若用户名相同,就回显到注册页面,并清空用户名;不同,则注册成功。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>请求注册页面</title>
</head>
<body>
<%
String InformationA = request.getParameter("text1");//用于回显时接收信息
String InformationB = request.getParameter("text2");
String InformationC = request.getParameter("text3");
if (InformationA == null)//在初始化时,去除信息等于空的情况,否则,页面一开始时文本框会显示null
InformationA = "";
else InformationA="";//回显时,消除用户名
if (InformationB == null)
InformationB = "";
if (InformationC == null)
InformationC = "";
%>
<h1>请求登录页面</h1>
<hr>
<form action="01b.jsp" method="post">//提交表单,传送信息
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="text1" value="<%=InformationA%>"></td>
</tr>
<tr>
<td>真实姓名:</td>
<td><input type="text" name="text2" value="<%=InformationB%>"></td>
</tr>
<tr>
<td>地址:</td>
<td><input type="text" name="text3" value="<%=InformationC%>"></td>
</tr>
<tr>
<td><input type="submit" value="确认"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录成功页面</title>
</head>
<body>
<h1>登录成功页面</h1>
<hr>
<%
String WebName = request.getParameter("text1");//接收信息
String RealName = request.getParameter("text2");
String Address = request.getParameter("text3");
if (WebName.equals("myname")||!WebName.equals(null)) {//判断用户名是否重复
%>
<jsp:forward page="01a.jsp"></jsp:forward>
<%
} else {
%>
<%
out.println("注册成功!!");
}
%>
</body>
</html>