今天主要是数据库的连接跟界面的优化;
register.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"> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <html> <head> <title>添加用户</title> <meta http-equiv="Content-Type"content="text/html; charset=UTF-8"> <meta name="viewport"content="width=device-width, initial-scale=1.0"> <link rel="stylesheet"type="text/css"href="${pageContext.request.contextPath}/static/bootstrap-3.3.5-dist/css/bootstrap.css"/> </head> <!-- 自定义,表单验证 --> <script src="${pageContext.request.contextPath}/static/js/jquery-1.12.1.js"type="text/javascript"></script> <script src="${pageContext.request.contextPath}/static/bootstrap-3.3.5-dist/js/bootstrap.js"type="text/javascript"></script> <script src="${pageContext.request.contextPath}/static/js/jquery.validate.js"type="text/javascript"></script> <script src="${pageContext.request.contextPath}/static/js/myValidate.js"type="text/javascript"></script> <body> <h1 align="center">用户注册</h1> <hr> <div class="row-fluid"style="margin-top: 80px;"> <div class="col-md-3"></div> <div class="col-md-6"> <form role="form"class="form-horizontal" action="${pageContext.request.contextPath}/admin/adminServlet?method=reg&updateId=${updateBean.username }"method="post" id="checkForm"> <div class="form-group"> <label class="col-md-3 control-label"for="username"><font style="color:red">*</font>用户名</label> <div class="col-md-9"> <input class="form-control" name="username" type="text" id="username"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="inputPassword"><font style="color:red">*</font>用户密码</label> <div class="col-md-9"> <input type="password"name="password"class="form-control"id="password"value="${updateBean.password }"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="password2"><font style="color:red">*</font>确认密码</label> <div class="col-md-9"> <input type="password"name="password2"class="form-control"id="password2"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="truename"><font style="color:red">*</font>姓名</label> <div class="col-md-9"> <input type="text"name="truename"class="form-control"id="truename"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="cardid"><font style="color:red">*</font>身份证号</label> <div class="col-md-9"> <input type="text"name="cardid"class="form-control"id="cardid"> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="city"><font style="color:red">*</font>市</label> <div class="col-md-9"> <select name="city"> <option value="石家庄市" checked="checked">石家庄市</option> <option value="唐山市">唐山市</option> <option value="秦皇岛市">秦皇岛市</option> <option value="邯郸市">邯郸市</option> <option value="邢台市">邢台市</option> <option value="保定市">保定市</option> <option value="张家口市">张家口市</option> <option value="承德市">承德市</option> <option value="沧州市">沧州市</option> <option value="廊坊市">廊坊市</option> <option value="衡水市">衡水市</option> <option value="定州市">定州市</option> <option value="辛集市">辛集市</option> <option value="其他(河北工大)">其他(河北工大)</option> </select> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="depart"><font style="color:red">*</font>工作单位</label> <div class="col-md-9"> <input class="form-control"name="depart"type="text"id="depart"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="director"><font style="color:red">*</font>专业方向</label> <div class="col-md-9"> <input class="form-control"name="director"type="text"id="director"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="hangye"><font style="color:red">*</font>所在行业</label> <div class="col-md-9"> <input class="form-control"name="hangye""type="text"id="hangye"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="education">教育程度</label> <div class="col-md-9"> <input class="form-control"name="education""type="text"id="education"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="zhicheng">职称</label> <div class="col-md-9"> <input class="form-control"name="zhicheng""type="text"id="zhicheng"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="address">通讯地址</label> <div class="col-md-9"> <input class="form-control"name="address""type="text"id="address"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="e_code">邮政编码</label> <div class="col-md-9"> <input class="form-control"name="e_code""type="text"id="e_code"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="Pnumber">手机号</label> <div class="col-md-9"> <input class="form-control"name="Pnumber"type="text"id="Pnumber"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="dianhua">固定电话</label> <div class="col-md-9"> <input class="form-control"name="dianhua"type="text"id="dianhua"value="${updateBean.username }"/> </div> </div> <div class="form-group"> <label class="col-md-3 control-label"for="email">邮箱</label> <div class="col-md-9"> <input type="text"name="email"class="form-control"id="email"> </div> </div> <div class="form-group"></div> <div class="form-group"> <div class="col-md-offset-3 col-md-9"> <button type="submit"class="btn btn-primary btn-block">注册</button> </div> </div> <!-- 注册成功或失败后的通知 --> <c:if test="${param.status.equals('1')}"> <script type="text/javascript"> function error() { alert('注册成功!!!'); self.location='login.jsp'; } error(); </script> </c:if> <c:if test="${param.status.equals('2')}"> <div class="alert alert-danger"role="alert">注册失败</div> </c:if> <c:if test="${param.status.equals('3')}"> <div class="alert alert-danger"role="alert">用户已存在</div> </c:if> </form> </div> <div class="col-md-3"></div> </div> </body> </html>
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!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=gb2312"> <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/css/xcConfirm.css"/> <script src="${pageContext.request.contextPath}/js/js/jquery-1.9.1.js" type="text/javascript" charset="utf-8"></script> <script src="${pageContext.request.contextPath}/js/js/xcConfirm.js" type="text/javascript" charset="utf-8"></script> <style type="text/css"> <!-- body { margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; background-image: url(images/loginbg.jpg); background-repeat: repeat-x; } --> </style> <style type="text/css"> .code { background-image:url(code.jpg); font-family:Arial; font-style:italic; color:Red; border:0; padding:2px 3px; letter-spacing:3px; font-weight:bolder; } .unchanged { border:0; } </style> <script type="text/javascript"> var code ; //在全局 定义验证码 function createCode() { code = ""; var codeLength = 6;//验证码的长度 var checkCode = document.getElementById("checkCode"); var selectChar = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');//所有候选组成验证码的字符,当然也可以用中文的 for(var i=0;i<codeLength;i++) { var charIndex = Math.floor(Math.random()*36);//生成0到36的随机数 code +=selectChar[charIndex];//将随机数连成字符串, 生成随机数 } //alert(code); if(checkCode) // { checkCode.className="code"; checkCode.value = code; } } function validateCode() { var inputCode=document.getElementById("codeCheck").value; if(inputCode.length <= 0) { var txt= "请输入验证码!"; window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success); } else if(inputCode.toUpperCase() != code.toUpperCase()) { var txt= "验证码输入有误!"; window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success); createCode(); } else { document.login.submit(); } } </script> </head> <body bgcolor="#FFFFFF" onload="createCode()"> <!-- Save for Web Slices (待切.psd) --> <form role="form" class="form-horizontal" action="${pageContext.request.contextPath}/admin/adminServlet?method=login" name="login" method="post" id="checkForm"> <table width="795" height="475" border="0" align="center" cellpadding="0" cellspacing="0" id="__01"> <tr> <td colspan="5"> <img src="images/login_01.jpg" width="795" height="159" alt=""></td> </tr> <tr> <td rowspan="2"> <img src="images/login_02.jpg" width="269" height="174" alt=""></td> <td bgcolor="#CFE5F2"> <img src="images/login_03.jpg" width="66" height="115" alt=""></td> <td colspan="2" bgcolor="#D0E6F3"><table width="100%" height="116" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" align="left" valign="bottom"><input name="username" onclick="J.calendar.get({dir:'right'});" TYPE="text" CLASS="STYLE1" id="username" STYLE="180px; height:17px; border:#336699 1px solid" tabindex="1" MAXLENGTH="26"></td> </tr> <tr> <td height="32" colspan="2" align="left" valign="bottom"><input name="password" TYPE="password" id="password" CLASS="STYLE1" STYLE="180px; height:17px; border:#336699 1px solid" tabindex="1" MAXLENGTH="26"></td> </tr> <tr> <td width="50%" height="29" align="left" valign="bottom"><INPUT name="codeCheck" id="codeCheck" TYPE="text" CLASS="STYLE1" STYLE="100px; height:17px; border:#336699 1px solid" tabindex="1" MAXLENGTH="26" id="codeCheck"></td> <td width="50%" align="left" valign="bottom"><input type="text" oncopy="return false" onclick="createCode()" readonly="readonly" id="checkCode" class="unchanged" style=" 75px" /></td> </tr> <tr> <td height="30" colspan="1" align="left" valign="bottom"> </td> </tr> </table></td> <td rowspan="2"> <img src="images/login_05.jpg" width="262" height="174" alt=""></td> </tr> <tr> <td colspan="2"><a href="#" onclick="validateCode()" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image12','','images/loging000_06.jpg',1)"><img src="images/login_06.jpg" name="Image12" width="135" height="59" border="0"></a></td> <td><a href="register.jsp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image13','','images/loging000_07.jpg',1)"><img src="images/login_07.jpg" name="Image13" width="129" height="59" border="0"></a></td> </tr> <tr> <td colspan="5"> <img src="images/login_08.jpg" width="795" height="141" alt=""></td> </tr> <tr> <td> <img src="images/分隔符.gif" width="269" height="1" alt=""></td> <td> <img src="images/分隔符.gif" width="66" height="1" alt=""></td> <td> <img src="images/分隔符.gif" width="69" height="1" alt=""></td> <td> <img src="images/分隔符.gif" width="129" height="1" alt=""></td> <td> <img src="images/分隔符.gif" width="262" height="1" alt=""></td> </tr> </table> </form> <!-- End Save for Web Slices --> <c:if test="${param.status.equals('1')}"> <script type="text/javascript"> function error() { var txt= "密码或用户名错误"; window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.success); } error(); </script> </c:if> <script src="${pageContext.request.contextPath}/static/js/jquery-1.12.1.js" type="text/javascript"></script> <script src="${pageContext.request.contextPath}/static/bootstrap-3.3.5-dist/js/bootstrap.js" type="text/javascript"></script> <script src="${pageContext.request.contextPath}/static/js/jquery.validate.js" type="text/javascript"></script> <script src="${pageContext.request.contextPath}/static/js/myValidate.js" type="text/javascript"></script> </body> </html>