目录
实验内容
制作一个登陆表单页面1,输入账号和密码,如果账号密码相等(如果同学们使用数据库访问判断账号密码则更好)则重定向到页面2,否则在页面1输出登录失败
在页面2中用一个下拉菜单(采用其它方式也可以)选择背景颜色,提交到页面3显示欢迎页面,背景颜色使用页面2选择的颜色,下次用户直接访问欢迎页面时,要直接显示选中的颜色,无需重新选择(判断是否已经有对应的cookie存在,有则无需再进入页面2),如果要修改默认颜色可以在页面1点击设置再进入页面2重新设置
代码和现象
1.登陆表单页面1
(1)代码编写
<%@ page contentType="text/html;charset=gb2312" language="java" %>
<html>
欢迎登录本系统<br>
<body align="center">
<form name="loginForm" action="1_passwordForm_result.jsp" method="post">
请您输入账号:<input name = "account" type="text"><br>
请您输入密码:<input name = "password" type="password"><br>
<input type = "button" onclick="validate()" value="登录">
<input type = "button" onclick="window.location.href='2_background.jsp'" value="修改背景颜色">
</form>
<script type="text/javascript">
function validate(){
account = document.loginForm.account.value;
password = document.loginForm.password.value;
if(account==""){
alert("账号不能为空");
document.loginForm.account.focus();
return ;
}
else if(password==""){
alert("密码不能为空");
document.loginForm.password.focus();
return ;
}
else{
if(account=="12345678"&&password=="111111"){
// alert("用户"+account+"登录成功");
window.location.replace("2_background.jsp");
// document.loginForm.submit();
}
else{
alert("账号或密码错误")
return ;
}
return ;
}
}
</script>
</body>
</html>
(2)网页效果展示
![在这里插入图片描述](
daj