Jsp第四次作业2
enter.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>登录</title> </head> <STYLE type="text/css"> td{font-size:12px} </STYLE> <SCRIPT type="text/javascript"> function checkLogin(){ var userName=document.myform.userid.value; var userPass=document.myform.passwd.value; var vegName=/^[a-zA-Z0-9]+$/; if(!vegName.test(userName)){ alert("用户名错误,请重新输入"); document.myform.userid.focus(); return false; } var regPwd=/^\w{6,}$/; if(!regPwd.test(userPass)){ alert("密码输入错误,请重新输入"); document.myform.passwd.select(); return false; } return true; } </SCRIPT> </HEAD> <BODY> <FORM NAME="myform" METHOD="POST" action="load2.jsp" > <TABLE align="center"> <TR> <TD> <IMG src="Snap1.jpg"><DIV style="position:absolute; left: 490px; top: 216px; width: 356px;"> <TABLE width="100%" height="100%" border=0 cellPadding=0 cellSpacing=0> <TBODY> <TR vAlign=top> <TD width="23%" height=27 align=right class=bld>用户名: </TD> <TD height="27" align=left><INPUT TYPE="text" SIZE="20" NAME="userid"><BR>用户名由字母和数字组成</TD> </TR> <TR vAlign=top> <TD class=bld align=right height=27>密码: </TD> <TD height="27" align=left><INPUT TYPE="password" SIZE="20" NAME="passwd"><BR>密码由字母、数字和下划线组成,至少6位</TD> </TR> <TR vAlign=top> <TD class=bld align=right height=40> </TD> <TD align=left valign="middle"><A href="#"><INPUT name="submit" type="image" src="login.gif" width="101" height="22" border="0" ></A> </TD> </TR> </TABLE></DIV> </TD> </TR> </TABLE> </FORM> </BODY> </HTML>
load2.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% String name=request.getParameter("userid"); String upw=request.getParameter("passwd"); if(name.equals("lucky")&&upw.equals("123456")){ //跳转到ok页面 request.getRequestDispatcher("ok.jsp").forward(request, response); }else{ //跳转到No页面 request.getRequestDispatcher("no.jsp").forward(request, response); } %>
ok.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> 你好:lucky! </body> </html>
no.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <html> <body> 登陆失败! <form name="form1" method="post" action="enter.jsp"> <tr > <td colspan="2" align="center" > <input type="submit" name="Submit" value="重新登录"> </td> </tr> </form> </body> </html>