再冲刺
在完成上一次的冲刺后,这次,我们组根据本学期新学习的javaweb语言编写了我们的登录界面。
编写的登录界面代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登陆首页</title>
</head>
<body>
<form name="form1" action="check.jsp" method="post">
用户名:<input name="name" type="text" />
<p>
密 码:<input name="pwd" type="password" />
<p>
验证码:<input name="yanzheng" type="text" size="8"/>
<%
int intmethod=(int) ((((Math.random())*11))-1);
int intmethod2=(int) ((((Math.random())*11))-1);
int intmethod3=(int) ((((Math.random())*11))-1);
int intmethod4=(int) ((((Math.random())*11))-1);
String intsum=intmethod+""+intmethod2+intmethod3+intmethod4;
%>
<input type="hidden" name="vcode" value="<%=intsum %>">
<img src="num/<%=intmethod%>.gif"> <img src="num/<%=intmethod2%>.gif">
<img src="num/<%=intmethod3%>.gif"> <img src="num/<%=intmethod4%>.gif">
<br><br>
<input name="submit" type="submit" value="登陆" onClick="return mycheck()">
<input name="submit1" type="reset" value="重置">
</form>
<script type="text/javascript">
function mycheck(){
if(form1.name.value=="")
{
alert("请输入用户名!");
form1.name.focus();
return false;
}
if(form1.pwd.value=="")
{
alert("请输入密码!");
form1.pwd.focus();
return false;
}
if(form1.yanzheng.value=="")
{
alert("请输入验证码!");
form1.yanzheng.focus();
return false;
}
if(form1.yanzheng.value!=form1.vcode.value)
{
alert("请输入正确的验证码!");
form1.yanzheng.focus();
return false;
}
form1.submit();
}
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:useBean id="userbean" class="com.wgh.UserBean"></jsp:useBean>
<jsp:setProperty property="name" name="userbean"/>
<jsp:setProperty property="pwd" name="userbean"/>
<jsp:setProperty property="yanzheng" name="userbean"/>
<jsp:setProperty property="vcode" name="userbean"/>
<title>在此处插入标题</title>
</head>
<body>
<%
/*String user=(String)request.getParameter("username");
String username=user.toString();
String pwd=(String)request.getParameter("pwd");
String pwd1=pwd.toString(); */
// String yzm=request.getParameter("yanzheng");
//得到session
HttpSession session1=request.getSession(true);
//将信息保存在session范围
session1.setAttribute("username", userbean.getName());
session1.setAttribute("pwd", userbean.getPwd());
session1.setAttribute("yanzheng", userbean.getYanzheng());
session1.setAttribute("vcode", userbean.getVcode());
//equal是字符类型使用,==是整数类型使用
if(userbean.getName().equals("wc")&&userbean.getPwd().equals("123")&&userbean.getYanzheng()==userbean.getVcode()){
response.sendRedirect("succ.jsp");}
else
response.sendRedirect("fail.jsp");
%>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>在此处插入标题</title>
</head>
<body>
<%
//得到session
HttpSession session1=request.getSession(true);
//得到sesson的id号
String sessionid=session1.getId();
//将信息保存在session范围
session.setAttribute("username", "wxx");
out.print(sessionid);
//输出保存在session中获取的信息
out.print(session.getAttribute("username"));
%>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>在此处插入标题</title>
</head>
<body>
<%String username=(String)session.getAttribute("username");
out.println(username);
%>
登陆成功!
<%
int number=0;
if(application.getAttribute("number")==null){
number=1;
}else{
number=Integer.parseInt(application.getAttribute("number").toString());
number=number+1;
}
out.print("您是第"+number+"位访问者");
%>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>在此处插入标题</title>
</head>
<body>
登陆失败!
<a href="login.jsp">返回</a>
</body>
</html>
以上就是登录界面所有代码,现在还不是太完善,等到了后期,我们会将我们的界面进行美化与完善。