当前位置:网站首页>实现页面与页面之间的信息交换
实现页面与页面之间的信息交换
2022-07-21 05:19:00 【疯子佳人傻了】
建立一个新的WEB工程,再建立一个Register.jsp和Accept.jsp。
1)程序功能:实现页面与页面之间的信息交换。
(2)程序源代码如下。
Register.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<script language="javascript">
function on_submit()
{//验证数据的合法性
if (form1.username.value == "")
{
alert("用户名不能为空,请输入用户名!");
form1.username.focus();
return false;
}
if (form1.userpassword.value == "")
{
alert("用户密码不能为空,请输入密码!");
form1.userpassword.focus();
return false;
}
if (form1.reuserpassword.value == "")
{
alert("用户确认密码不能为空,请输入密码!");
form1.reuserpassword.focus();
return false;
}
if (form1.userpassword.value != form1.reuserpassword.value)
{
alert("密码与确认密码不同");
form1.userpassword.focus();
return false;
}
if (form1.email.value.length!= 0)
{
for (i=0; i<form1.email.value.length; i++)
if (form1.email.value.charAt(i)=="@")
break;
if (i==form1.email.value.length)
{
alert("非法EMail地址!");
form1.email.focus();
return false;
}
}
else
{
alert("请输入Email!");
form1.email.focus();
return false;
}
}
</script>
<html>
<head>
<title>新用户注册</title>
</head>
<body>
<form method="POST" action=" Accept.jsp" name="form1" οnsubmit="return on_submit()">
新用户注册<br>
用户名(*):<input type="text" name="username" size="20"><br>
密 码(*):<input type="password" name="userpassword" size="20"><br>
再输一次密码(*):<input type="password" name="reuserpassword" size="20"><br>
性别:<input type="radio" value="男" checked name="sex">男<input type="radio" name="sex" value="女">女<br>
出生年月:<input name="year" size="4" maxlength=4>年
<select name="month">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="8">7</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>月
<input name="day" size="3" maxlength=4>日<br>
电子邮箱(*):<input name="email" maxlength=28><br>
家庭住址:<input type="text" name="address" size="20"><br>
<input type="submit" value="提交" name="B1"><input type="reset" value="全部重写" name="B2"><br>
</form>
</body>
</html>
Accept.jsp
<%@ page contentType="text/html;charset=gb2312"%>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<html>
<head>
<title>接收新用户注册</title>
</head>
<body>
这是新用户注册所提交的数据:
<br>
用户名是:<%=codeToString(request.getParameter("username"))%><br>
密码是:<%=codeToString(request.getParameter("userpassword"))%><br>
性别是:<%=codeToString(request.getParameter("sex"))%><br>
出生年月是:<%=request.getParameter("year")+request.getParameter("month")+request.getParameter("day")%><br>
电子邮箱是:<%=request.getParameter("email")%><br>
家庭住址是:<%=codeToString(request.getParameter("address"))%><br>
</body>
</html>
2.部署并浏览该页面。
边栏推荐
- Jenkins continuous integration automation test practice (Part 2)
- No idea about interface testing? An article to teach you how to handle the interview
- Jenkins持续集成自动化测试实战(上篇)
- Motion recovery structure (3D reconstruction task3-1)
- MySQL classic interview questions 14
- 运动恢复结构(三维重建task3-1)
- Watermelon book chapter 3 - linear model
- Super detailed - working principle of NMOS and PMOS and related content sorting (Part 1)
- 遵守指南,快速提升自己:功能测试如何快速转向自动化测试
- After modifying the IP address, use ifconfig on the terminal to check that the IP address is not updated
猜你喜欢
随机推荐
视图
Modify the coding format again after creating the table
产品总是临时加需求,怎么办
jmeter脚本生成基于rap2
004_ SSSS_ Image-to-Image Translation with Conditional Adversarial Networks
Software test 49 must ask interview questions + Answers
STM32 series timer complementary output details
Jenkins搭建
软件测试49个必问面试题合集+答案
Have you seen the open source data visualization community comparable to the "fairy fight"?
Install and upgrade sysstat to version 11.5.5
文件下载,用例怎么写?
如何做 APP 升级测试 ?
文件上传,用例怎么写?
Postman's solution to "failed to obtain token through data.token in tests"
C语言运用函数七大极易忽略的结论
005_ SS_ Palette Image-to-Image Diffusion Models
Great reward for data visualization chart plug-in development works (I)
知秋
Postman工具的灵活运用