作业一
index
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <FORM action="jsp2.jsp" method="post" name="myform"> <TABLE border="0" cellpadding="0" cellspacing="0" align="center" width="530"> <TR> <TD height="108" colspan="2"><IMG src="images/top.jpg"></TD> </TR> <TR> <TD width="107" height="36">用户名:</TD> <TD width="524"><INPUT name="txtUser" type="text" maxlength="16">只能输入字母或数字,4-16个字符</TD> </TR> <TR> <TD width="107" height="36">密码:</TD> <TD width="524"><INPUT name="txtPass" type="password">密码长度6-12位</TD> </TR> <TR> <TD width="107" height="36">确认密码:</TD> <TD width="524"><INPUT name="txtRPass" type="password"></TD> </TR> <TR> <TD width="107" height="36">性别:</TD> <TD width="524"> <INPUT name="gen" type="radio" value="男" checked>男 <INPUT name="gen" type="radio" value="女" class="input">女 </TD> </TR> <TR> <TD width="117" height="36">电子邮件地址:</TD> <TD width="524"><INPUT name="txtEmail" type="text"> 输入正确的Email地址</TD> </TR> <TR> <TD width="107" height="36">出生日期:</TD> <TD width="524"> <INPUT name="year" id="year" size="4" maxlength="4" > 年 <SELECT name="month" > <OPTION value=1>一月</OPTION> <OPTION value=2>二月</OPTION> <OPTION value=3>三月</OPTION> <OPTION value=4>四月</OPTION> <OPTION value=5>五月</OPTION> <OPTION value=6>六月</OPTION> <OPTION value=7>七月</OPTION> <OPTION value=8>八月</OPTION> <OPTION value=9>九月</OPTION> <OPTION value=10>十月</OPTION> <OPTION value=11>十一月</OPTION> <OPTION value=12>十二月 </OPTION> </SELECT> 月 <SELECT name="day" > <OPTION value=1>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=7>7</OPTION><OPTION value=8>8</OPTION> <OPTION value=9>9</OPTION><OPTION value=10>10</OPTION><OPTION value=11>11</OPTION><OPTION value=12>12 </OPTION> <OPTION value=13>13</OPTION><OPTION value=14>14</OPTION><OPTION value=15>15</OPTION><OPTION value=16>16</OPTION> <OPTION value=17>17</OPTION><OPTION value=18>18</OPTION><OPTION value=19>19</OPTION><OPTION value=20>20</OPTION> <OPTION value=21>21</OPTION><OPTION value=22>22</OPTION><OPTION value=23>23</OPTION><OPTION value=24>24</OPTION> <OPTION value=25>25</OPTION><OPTION value=26>26</OPTION><OPTION value=27>27</OPTION><OPTION value=28>28</OPTION> <OPTION value=29>29</OPTION><OPTION value=30>30</OPTION><OPTION value=7>31</OPTION> </SELECT> 日 </TD> </TR> <TR><TD colspan="2" align="center"> <INPUT type="submit" value="同意以下协议条款并提交"> </TD></TR> <TR><TD colspan="2"> <TEXTAREA cols="" rows="" readonly="readonly" style="480px;height:110px;font-size:12px;color:#666"> 一、总则 1.1 用户应当同意本协议的条款并按照页面上的提示完成全部的注册程序。用户在进行注册程序过程中点击"同意"按钮即表示用户与百度公司达成协议,完全接受本协议项下的全部条款。 1.2 用户注册成功后,百度将给予每个用户一个用户帐号及相应的密码,该用户帐号和密码由用户负责保管;用户应当对以其用户帐号进行的所有活动和事件负法律责任。 1.3 用户可以使用百度各个频道单项服务,当用户使用百度各单项服务时,用户的使用行为视为其对该单项服务的服务条款以及百度在该单项服务中发出的各类公告的同意。 1.4 百度会员服务协议以及各个频道单项服务条款和公告可由百度公司随时更新,且无需另行通知。您在使用相关服务时,应关注并遵守其所适用的相关条款。 您在使用百度提供的各项服务之前,应仔细阅读本服务协议。如您不同意本服务协议及/或随时对其的修改,您可以主动取消百度提供的服务;您一旦使用百度服务,即视为您已了解并完全同意本服务协议各项内容,包括百度对服务协议随时所做的任何修改,并成为百度用户。 </TEXTAREA> </TD> </TR> </TABLE> </FORM> </body> </html>
index2
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index2.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% request.setCharacterEncoding("utf-8"); String name=request.getParameter("txtUser"); String psd=request.getParameter("txtPass"); String sex=request.getParameter("gen"); String email=request.getParameter("txtEmail"); String year=request.getParameter("year"); String month=request.getParameter("month"); String day=request.getParameter("day"); %> <h3>您注册的信息如下:</h3><br> 用户名:<%=name %><br> 密码:<%=psd %><br> 性别:<%=sex %><br> 电子邮件:<%=email %><br> 出生日期:<%=year %>年<%=month %>月<%=day %>日 </body> </html>
作业二
index
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML> <HEAD> <base href="<%=basePath%>"> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>登录验证</TITLE> <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="MyJsp.jsp" onSubmit="checkLogin()"> <TABLE align="center"> <TR> <TD> <IMG src="images/Snap1.jpg"><DIV style="position:absolute; left: 490px; top: 216px; 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="images/login.gif" width="101" height="22" border="0" ></A> </TD> </TR> </TABLE></DIV> </TD> </TR> </TABLE> </FORM> </BODY> </html>
MyJsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'MyJsp.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% request.setCharacterEncoding("utf-8"); String id= request.getParameter("userid"); String pwd= request.getParameter("passwd"); if(id.equals("lucky")&&pwd.equals("123456")){ response.sendRedirect("MyJsp1.jsp"); }else{ response.sendRedirect("MyJsp2.jsp"); } %> <br> </body> </html>
MyJsp1
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'MyJsp1.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 你好:lucky <br> </body> </html>
MyJsp2
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'MyJsp2.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 登录失败 <br> <a href="index.jsp"> <input type="button" value="重新登录"> </a> <br> </body> </html>