1 import java.sql.Connection; 2 import java.sql.DriverManager; 3 import java.sql.ResultSet; 4 import java.sql.SQLException; 5 import java.sql.Statement; 6 7 public class DBUtil { 8 static String driver = "oracle.jdbc.driver.OracleDriver"; 9 static String url = "jdbc:oracle:thin:@localhost:1521:orcl"; 10 static String username = "superyang"; 11 static String password = "orcl"; 12 13 //==========添加驱动,连接数据库 方法============================== 14 public static Connection getConnection(){ 15 Connection conn = null; 16 17 try { //1.添加驱动 18 Class.forName(driver); 19 } catch (ClassNotFoundException e) { 20 e.printStackTrace(); 21 } 22 try { //2.创建数据库连接对象 23 conn = DriverManager.getConnection(url,username,password); 24 } catch (SQLException e) { 25 e.printStackTrace(); 26 } 27 return conn; 28 } 29 30 //==========释放资源方法===================================== 31 public static void free(ResultSet rs,Statement sm,Connection conn){ 32 33 try { 34 35 if(rs!=null){ 36 rs.close(); 37 } 38 39 if(sm!=null){ 40 sm.close(); 41 } 42 43 if(conn!=null){ 44 conn.close(); 45 } 46 } catch (SQLException e) { 47 e.printStackTrace(); 48 } 49 50 } 51 }
1 import java.awt.Color; 2 import java.awt.Font; 3 import java.awt.Graphics; 4 import java.awt.image.BufferedImage; 5 import java.io.IOException; 6 import java.util.Random; 7 import javax.imageio.ImageIO; 8 import javax.servlet.ServletException; 9 import javax.servlet.http.HttpServlet; 10 import javax.servlet.http.HttpServletRequest; 11 import javax.servlet.http.HttpServletResponse; 12 import javax.xml.ws.Response; 13 14 public class ImageServlet extends HttpServlet{ 15 @Override 16 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 17 //通知浏览器不要缓存 18 resp.setHeader("Expires", "-1"); 19 resp.setHeader("Cache-Control", "no-cache"); 20 resp.setHeader("Prama", "no-cache"); 21 22 int width=120; 23 int height=50; 24 //在内存中创建一幅图 25 BufferedImage bu = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB); 26 //得到一个画笔 27 Graphics gr = bu.getGraphics(); 28 //画边框 29 gr.setColor(Color.gray); 30 gr.drawRect(0, 0, width, height); 31 //背景 32 gr.setColor(Color.pink); 33 gr.fillRect(1, 1, width-2, height-2); 34 //干扰线 35 Random ran = new Random(); 36 gr.setColor(Color.black); 37 for(int i=0;i<=10;i++){ 38 gr.drawLine(ran.nextInt(width), ran.nextInt(height), ran.nextInt(width), ran.nextInt(height)); 39 } 40 //验证码 41 gr.setColor(Color.red); 42 gr.setFont(new Font("宋体", Font.BOLD|Font.ITALIC, 35)); 43 int x =18; 44 String s =""; 45 for(int j=0;j<4;j++){ 46 s+=ran.nextInt(10)+""; 47 gr.drawString(s.substring(j,j+1), x, 35); 48 x+=25; 49 50 } 51 req.getSession().setAttribute("racode", s); 52 //System.out.println(s); 53 //输出到网页上 54 ImageIO.write(bu, "jpg", resp.getOutputStream()); 55 } 56 57 58 59 @Override 60 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 61 this.doGet(req, resp); 62 } 63 64 65 66 }
1 import java.io.IOException; 2 import java.sql.Connection; 3 import java.sql.PreparedStatement; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 public class Register extends HttpServlet{ 13 @Override 14 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 15 req.setCharacterEncoding("UTF-8"); 16 resp.setCharacterEncoding("UTF-8"); 17 String rid = req.getParameter("rid"); //得到请求参数 18 String rname = req.getParameter("rname"); 19 String rsex = req.getParameter("rsex"); 20 String rage = req.getParameter("rage"); 21 String raddress = req.getParameter("raddress"); 22 String rpass = req.getParameter("rpass"); 23 String rsf = req.getParameter("rsf"); 24 25 Connection conn = DBUtil.getConnection(); 26 PreparedStatement ps = null; 27 ResultSet rs = null; 28 String sql = "insert into users values(?,?,?,?,?,?,?)"; 29 try { 30 ps = conn.prepareStatement(sql); 31 ps.setString(1, rid); 32 ps.setString(2, rname); 33 ps.setString(3, rsex); 34 ps.setString(4, rage); 35 ps.setString(5, raddress); 36 ps.setString(6, rpass); 37 ps.setString(7, rsf); 38 39 int i =ps.executeUpdate(); 40 if(i>0){ 41 42 //req.setAttribute("reg", "reg"); 43 resp.sendRedirect("regi.jsp"); 44 }else{ 45 System.out.println("用户操作失败"); 46 resp.sendRedirect("index.jsp"); 47 } 48 DBUtil.free(rs, ps, conn); 49 } catch (SQLException e) { 50 //e.printStackTrace(); 51 System.out.println("用户异常操作失败"); 52 resp.sendRedirect("index.jsp"); 53 } 54 55 56 } 57 @Override 58 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 59 this.doPost(req, resp); 60 } 61 }
1 import java.io.IOException; 2 import java.sql.Connection; 3 import java.sql.PreparedStatement; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 public class Login extends HttpServlet { 13 @Override 14 public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 15 req.setCharacterEncoding("UTF-8"); 16 resp.setCharacterEncoding("UTF-8"); 17 String uid = req.getParameter("uid"); //得到请求参数 18 String upass = req.getParameter("upass"); 19 String usf = req.getParameter("usf"); 20 String code = req.getParameter("code"); 21 String racode = (String)req.getSession().getAttribute("racode"); 22 Connection conn = DBUtil.getConnection(); 23 PreparedStatement ps = null; 24 ResultSet rs = null; 25 boolean flog = false; 26 if(racode.equals(code)){ 27 //System.out.println(code+"==="+racode); 28 if(usf.equals("学生")){ 29 String sql = "select name from users where id=? and password=? and sf=?"; 30 try { 31 ps = conn.prepareStatement(sql); 32 ps.setString(1, uid); 33 ps.setString(2, upass); 34 ps.setString(3, usf); 35 rs = ps.executeQuery(); 36 while(rs.next()){ 37 System.out.println("学生登陆成功,2秒后跳转页面"); 38 req.getSession().setAttribute("showname", rs.getString(1)); 39 //req.getSession().setAttribute("ssf", "学生"); 40 if(rs.getString(1)==null){ 41 resp.sendRedirect("index.jsp"); 42 } 43 flog=true; 44 } 45 if(flog=false){ 46 System.out.println("登陆错误,请重新选择");// 47 resp.sendRedirect("index.jsp"); 48 }else{ 49 resp.sendRedirect("logins.jsp"); 50 } 51 } catch (Exception e) { 52 System.out.println("登陆错误,请重新选择"); 53 } 54 }else if(usf.equals("教师")){ 55 String sql = "select name from users where id=? and password=? and sf=?"; 56 try { 57 ps = conn.prepareStatement(sql); 58 ps.setString(1, uid); 59 ps.setString(2, upass); 60 ps.setString(3, usf); 61 rs = ps.executeQuery(); 62 while(rs.next()){ 63 System.out.println("教师登陆成功,2秒后跳转页面"); 64 req.getSession().setAttribute("showname", rs.getString(1)); 65 //req.setAttribute("tsf", "教师"); 66 if(rs.getString(1)==null){ 67 resp.sendRedirect("index.jsp"); 68 } 69 flog=true; 70 } 71 if(flog=false){ 72 System.out.println("登陆错误,请重新选择");// 73 resp.sendRedirect("index.jsp"); 74 }else{ 75 resp.sendRedirect("logint.jsp"); 76 } 77 } catch (SQLException e) { 78 e.printStackTrace(); 79 } 80 } 81 }else{ 82 System.out.println("验证码输入错误"); 83 } 84 } 85 @Override 86 public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 87 this.doGet(req, resp); 88 } 89 }
1 import java.io.IOException; 2 import java.sql.Connection; 3 import java.sql.PreparedStatement; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 public class Insertstu extends HttpServlet{ 13 @Override 14 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 15 req.setCharacterEncoding("UTF-8"); 16 resp.setCharacterEncoding("UTF-8"); 17 String rid = req.getParameter("rid"); //得到请求参数 18 String rname = req.getParameter("rname"); 19 String rsex = req.getParameter("rsex"); 20 String rage = req.getParameter("rage"); 21 String raddress = req.getParameter("raddress"); 22 String rpass = req.getParameter("rpass"); 23 String rsf = req.getParameter("rsf"); 24 25 Connection conn = DBUtil.getConnection(); 26 PreparedStatement ps = null; 27 ResultSet rs = null; 28 String sql = "insert into users values(?,?,?,?,?,?,?) and sf='学生'"; 29 try { 30 ps = conn.prepareStatement(sql); 31 ps.setString(1, rid); 32 ps.setString(2, rname); 33 ps.setString(3, rsex); 34 ps.setString(4, rage); 35 ps.setString(5, raddress); 36 ps.setString(6, rpass); 37 ps.setString(7, rsf); 38 39 int t =ps.executeUpdate(); 40 if(t>0){ 41 System.out.println("学生信息创建成功"); 42 //req.getSession().setAttribute("ins", "ins"); 43 resp.sendRedirect("success.jsp"); 44 }else{ 45 System.out.println("用户操作失败"); 46 resp.sendRedirect("error.jsp"); 47 48 } 49 50 } catch (SQLException e) { 51 //e.printStackTrace(); 52 System.out.println("用户操作异常失败"); 53 resp.sendRedirect("error.jsp"); 54 } 55 } 56 @Override 57 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 58 this.doPost(req, resp); 59 } 60 }
1 import java.io.IOException; 2 import java.sql.Connection; 3 import java.sql.PreparedStatement; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 import javax.servlet.ServletException; 7 import javax.servlet.http.HttpServlet; 8 import javax.servlet.http.HttpServletRequest; 9 import javax.servlet.http.HttpServletResponse; 10 11 public class Deletestu extends HttpServlet{ 12 @Override 13 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 14 req.setCharacterEncoding("UTF-8"); 15 resp.setCharacterEncoding("UTF-8"); 16 String rid = req.getParameter("rid"); //得到请求参数 17 18 Connection conn = DBUtil.getConnection(); 19 PreparedStatement ps = null; 20 ResultSet rs = null; 21 String sql = "delete from users where id=? and sf='学生'"; 22 try { 23 ps = conn.prepareStatement(sql); 24 ps.setString(1, rid); 25 int i =ps.executeUpdate(); 26 if(i>0){ 27 //req.setAttribute("del", "del"); 28 resp.sendRedirect("success.jsp"); 29 }else{ 30 System.out.println("用户操作失败"); 31 resp.sendRedirect("error.jsp"); 32 } 33 DBUtil.free(rs, ps, conn); 34 } catch (SQLException e) { 35 //e.printStackTrace(); 36 System.out.println("用户异常操作失败"); 37 resp.sendRedirect("error.jsp"); 38 } 39 } 40 @Override 41 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 42 this.doPost(req, resp); 43 } 44 }
1 import java.io.IOException; 2 import java.sql.Connection; 3 import java.sql.PreparedStatement; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 7 import javax.servlet.ServletException; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 public class Updatestu extends HttpServlet{ 13 @Override 14 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 15 req.setCharacterEncoding("UTF-8"); 16 resp.setCharacterEncoding("UTF-8"); 17 String rid = req.getParameter("rid"); //得到请求参数 18 String rname = req.getParameter("rname"); 19 String rsex = req.getParameter("rsex"); 20 String rage = req.getParameter("rage"); 21 String raddress = req.getParameter("raddress"); 22 String rpass = req.getParameter("rpass"); 23 String rsf = req.getParameter("rsf"); 24 25 Connection conn = DBUtil.getConnection(); 26 PreparedStatement ps = null; 27 ResultSet rs = null; 28 String sql = "update users set name=?,sex=?,age=?,address=?,password=?,sf=? where id=? and sf='学生'"; 29 try { 30 ps = conn.prepareStatement(sql); 31 ps.setString(1, rname); 32 ps.setString(2, rsex); 33 ps.setString(3, rage); 34 ps.setString(4, raddress); 35 ps.setString(5, rpass); 36 ps.setString(6, rsf); 37 ps.setString(7, rid); 38 int i =ps.executeUpdate(); 39 if(i>0){ 40 //req.setAttribute("upd", "upd"); 41 resp.sendRedirect("success.jsp"); 42 }else{ 43 System.out.println("用户操作失败"); 44 resp.sendRedirect("error.jsp"); 45 } 46 DBUtil.free(rs, ps, conn); 47 } catch (SQLException e) { 48 //e.printStackTrace(); 49 System.out.println("用户异常操作失败"); 50 resp.sendRedirect("error.jsp"); 51 } 52 } 53 @Override 54 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 55 this.doPost(req, resp); 56 } 57 }
1 import java.io.IOException; 2 import java.sql.Connection; 3 import java.sql.PreparedStatement; 4 import java.sql.ResultSet; 5 import java.sql.SQLException; 6 import javax.servlet.ServletException; 7 import javax.servlet.http.HttpServlet; 8 import javax.servlet.http.HttpServletRequest; 9 import javax.servlet.http.HttpServletResponse; 10 11 public class Selectstu extends HttpServlet{ 12 @Override 13 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 14 req.setCharacterEncoding("UTF-8"); 15 resp.setCharacterEncoding("UTF-8"); 16 String rid = req.getParameter("rid"); //得到请求参数 17 18 Connection conn = DBUtil.getConnection(); 19 PreparedStatement ps = null; 20 ResultSet rs = null; 21 String sql = "select * from users where id=? and sf='学生'"; 22 try { 23 ps = conn.prepareStatement(sql); 24 ps.setString(1, rid); 25 rs = ps.executeQuery(); //执行语句 26 while(rs.next()){ 27 28 req.getSession().setAttribute("id", rs.getString(1)); 29 req.getSession().setAttribute("name", rs.getString(2)); 30 req.getSession().setAttribute("sex", rs.getString(3)); 31 req.getSession().setAttribute("age", rs.getString(4)); 32 req.getSession().setAttribute("address", rs.getString(5)); 33 req.getSession().setAttribute("password", rs.getString(6)); 34 req.getSession().setAttribute("sf", rs.getString(7)); 35 } 36 int i =ps.executeUpdate(); 37 if(i>0){ 38 resp.sendRedirect("sele.jsp"); 39 }else{ 40 System.out.println("用户操作失败"); 41 resp.sendRedirect("error.jsp"); 42 } 43 DBUtil.free(rs, ps, conn); 44 } catch (SQLException e) { 45 System.out.println("用户异常操作失败"); 46 resp.sendRedirect("error.jsp"); 47 } 48 } 49 @Override 50 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 51 this.doPost(req, resp); 52 } 53 }
二:JSP
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>首页</title> 6 <script type="text/javascript" > 7 function tofresh(){ 8 document.location.href="index.jsp"; 9 } 10 var b=true; 11 function checkname(obj){ 12 var name = obj.value; 13 var pattern=/^d{4}$/; 14 if(name.match(pattern)==null){ 15 document.getElementById("user").innerHTML="<font color='red'>请输入4位数字ID</font>"; 16 document.getElementById("username").value=""; 17 b = false; 18 }else{ 19 document.getElementById("user").innerHTML="<font color='green'>ID合法</font>"; 20 21 } 22 } 23 function checkpass1(obj){ 24 var pass = obj.value; 25 var pattern=/^d{6}$/; 26 if(pass.match(pattern)==null){ 27 document.getElementById("pass1").innerHTML="<font color='red'>6位数字密码</font>"; 28 document.getElementById("pw1").value=""; 29 b = false; 30 }else{ 31 document.getElementById("pass1").innerHTML="<font color='green'>密码合法</font>"; 32 33 } 34 } 35 function checksf(obj){ 36 var sf = obj.value; 37 38 if((sf=="学生")||(sf=="教师")){ 39 document.getElementById("shenf").innerHTML="<font color='green'>已选择</font>"; 40 }else{ 41 document.getElementById("shenf").innerHTML="<font color='red'>请重新选择</font>"; 42 document.getElementById("sf").value=""; 43 b = false; 44 } 45 } 46 function checkyzm(obj){ 47 var name = obj.value; 48 var pattern=/^d{4}$/; 49 if(name.match(pattern)==null){ 50 document.getElementById("codeyzm").innerHTML="<font color='red'>请输入4位数字验证码</font>"; 51 document.getElementById("yzm").value=""; 52 b = false; 53 }else{ 54 document.getElementById("codeyzm").innerHTML="<font color='green'>验证码格式合法</font>"; 55 56 } 57 } 58 function subm(){ 59 return b; 60 } 61 </script> 62 63 </head> 64 <body bgcolor=rgb(180,205,230)> 65 <form action="login" method="post" onsubmit="return subm()"> 66 <div align="center"> 67 <h1>欢迎登陆学生管理系统</h1><hr color="red"><br/> 68 <table border="1" cellpadding="0" cellspacing="0" name="mytable" bgcolor="white"> 69 <tr> 70 <td>用户ID:</td> 71 <td><input type="text" name="uid" id="username" onblur="checkname(this)"></td> 72 <td><div id="user"><font color="red">*<font></div></td> 73 </tr> 74 <tr> 75 <td>登陆密码:</td> 76 <td><input type="password" name="upass" id="pw1" onblur="checkpass1(this)"></td> 77 <td><div id="pass1"><font color="red">*<font></div></td> 78 </tr> 79 <tr> 80 <td>登陆身份:</td> 81 <td> 82 <select name="usf" id="sf" onblur="checksf(this)"> 83 <option value="" selected="seleected">==请选择==</option> 84 <option value="学生" >学生</option> 85 <option value="教师" >教师</option> 86 </select> 87 </td> 88 <td><div id="shenf"><font color="red">*<font></div></td> 89 </tr> 90 <tr> 91 <td>验证码:</td> 92 <td><input type="text" name="code" id="yzm" onblur="checkyzm(this)"></td> 93 <td><div id="codeyzm"><font color="red">*<font></div></td> 94 </tr> 95 <tr> 96 <td><img alt="验证码" src="ImageServlet"></td> 97 <td><a href="javascript:tofresh()">看不清,请再换一张</a></td> 98 </tr> 99 </table> 100 <br/> 101 <input type="submit" value="登陆" > 102 <a href="register.jsp"><input type="button" value="注册"></a> 103 </div> 104 </form> 105 </body> 106 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>jump</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 13 <% 14 response.setHeader("refresh","2;smenu.jsp"); 15 %> 16 <h2>登陆成功,两秒后跳转</h2> 17 <h1>如果没有跳转,请点击<a href="smenu.jsp">这里</a></h1> 18 <% 19 }else{ 20 %> 21 <div align="right" class="fd"> 22 请先<a href="index.jsp">登录</a> 23 </div> 24 <% 25 } 26 %> 27 </body> 28 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>jump</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 13 <% 14 response.setHeader("refresh","2;tmenu.jsp"); 15 %> 16 <h2>登陆成功,两秒后跳转</h2> 17 <h1>如果没有跳转,请点击<a href="tmenu.jsp">这里</a></h1> 18 <% 19 }else{ 20 %> 21 <div align="right" class="fd"> 22 请先<a href="index.jsp">登录</a> 23 </div> 24 <% 25 } 26 %> 27 </body> 28 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>Insert title here</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 <% 13 session.invalidate(); 14 response.setHeader("refresh","1;index.jsp"); 15 %> 16 <h2>注销成功,</h2> 17 <h1>如果没有跳转,请点击<a href="index.jsp">这里</a></h1> 18 <% 19 }else{ 20 %> 21 <div align="right" class="fd"> 22 请先<a href="index.jsp">登录</a> 23 </div> 24 <% 25 } 26 %> 27 </body> 28 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>jump</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 9 <% 10 request.setCharacterEncoding("UTF-8"); 11 %> 12 <h2>操作出现错误。</h2> 13 14 </body> 15 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>Insert title here</title> 6 7 8 </head> 9 <body bgcolor=rgb(180,205,230)> 10 <% 11 request.setCharacterEncoding("UTF-8"); 12 if(session.getAttribute("showname")!=null){ 13 %> 14 <div align="right" class="fd"> 15 <%=session.getAttribute("showname") %> 16 <a href="index.jsp" >注销</a> 17 </div> 18 19 20 <ol> 21 22 <li>更改个人信息</li> 23 <li>查看个人信息</li> 24 </ol> 25 26 27 <% 28 }else{ 29 %> 30 <div align="right" class="fd"> 31 请先<a href="index.jsp">登录</a> 32 </div> 33 <% 34 } 35 %> 36 37 </body> 38 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>Insert title here</title> 6 7 </head> 8 <body bgcolor=rgb(180,205,230)> 9 10 <% 11 request.setCharacterEncoding("UTF-8"); 12 if(session.getAttribute("showname")!=null){ 13 %> 14 <div align="right" class="fd"> 15 <%=session.getAttribute("showname") %> 16 <a href="index.jsp" >注销</a> 17 </div> 18 <h1>学生管理界面</h1><hr color="red"><br/> 19 <ul> 20 <a href="insert_student.jsp" target="iframe_a"><li>添加学生信息</li></a> 21 <a href="delete_student.jsp" target="iframe_a"><li>删除学生信息</li></a> 22 <a href="update_student.jsp" target="iframe_a"><li>更改学生信息</li></a> 23 <a href="select_student.jsp" target="iframe_a"><li>查看学生信息</li></a> 24 25 </ul> 26 <div align="right"> 27 <iframe src="#" name="iframe_a" width="700" height="700" frameborder="0"> 28 </iframe> 29 </div> 30 <% 31 }else{ 32 %> 33 <div align="right" class="fd"> 34 请先<a href="index.jsp">登录</a> 35 </div> 36 <% 37 } 38 %> 39 40 </body> 41 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>jump</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 9 <% 10 request.setCharacterEncoding("UTF-8"); 11 %> 12 <h2>操作成功,请选择。</h2> 13 14 </body> 15 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>jump</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 13 <% 14 response.setHeader("refresh","2;index.jsp"); 15 %> 16 <h2>注册成功,两秒后跳转至首页</h2> 17 <h1>如果没有跳转,请点击<a href="index.jsp">这里</a></h1> 18 <% 19 }else{ 20 %> 21 <div align="right" class="fd"> 22 请先<a href="index.jsp">登录</a> 23 </div> 24 <% 25 } 26 %> 27 </body> 28 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>注册</title> 6 <script type="text/javascript" > 7 function checkid(obj){ 8 var id=obj.value; 9 var pa=/^d{4}$/; 10 if(id.match(pa)==null){ 11 document.getElementById("userid").innerHTML="<font color='red'>请输入4位数字ID</font>"; 12 document.getElementById("rid").value=""; 13 }else{ 14 document.getElementById("userid").innerHTML="<font color='green'>ID合法</font>"; 15 } 16 } 17 function checkname(obj){ 18 var name = obj.value; 19 var pa=/^D{1,20}$/; 20 if(name.match(pa)==null){ 21 document.getElementById("username").innerHTML="<font color='red'>请输入用户名</font>"; 22 document.getElementById("rname").value=""; 23 b = false; 24 }else{ 25 document.getElementById("username").innerHTML="<font color='green'>用户名合法</font>"; 26 } 27 } 28 function checksex(obj){ 29 var sex=obj.value; 30 var pa=/^D$/; 31 if(sex.match(pa)==null){ 32 document.getElementById("usersex").innerHTML="<font color='red'>请输入性别</font>"; 33 document.getElementById("rsex").value=""; 34 }else{ 35 document.getElementById("usersex").innerHTML="<font color='green'>性别输入合法</font>"; 36 } 37 } 38 function checkage(obj){ 39 var age = obj.value; 40 var pa=/^d{1,3}/; 41 if(age.match(pa)==null){ 42 document.getElementById("userage").innerHTML="<font color='red'>请输入年龄</font>"; 43 document.getElementById("rage").value=""; 44 b = false; 45 }else{ 46 document.getElementById("userage").innerHTML="<font color='green'>年龄输入合法</font>"; 47 } 48 } 49 function checkaddr(obj){ 50 var raddr = obj.value; 51 var pa=/^D{1,20}/; 52 if(raddr.match(pa)==null){ 53 document.getElementById("useraddr").innerHTML="<font color='red'>请输入地址</font>"; 54 document.getElementById("raddr").value=""; 55 b = false; 56 }else{ 57 document.getElementById("useraddr").innerHTML="<font color='green'>地址输入合法</font>"; 58 } 59 } 60 function checkpass(obj){ 61 var rpass = obj.value; 62 var pa=/^d{6}/; 63 if(rpass.match(pa)==null){ 64 document.getElementById("userpass").innerHTML="<font color='red'>请输入密码</font>"; 65 document.getElementById("rpass").value=""; 66 b = false; 67 }else{ 68 document.getElementById("userpass").innerHTML="<font color='green'>密码输入合法</font>"; 69 } 70 } 71 function checksf(obj){ 72 var rsf = obj.value; 73 74 if((rsf=="学生")||(rsf=="教师")){ 75 document.getElementById("usersf").innerHTML="<font color='green'>已选择</font>"; 76 }else{ 77 document.getElementById("usersf").innerHTML="<font color='red'>请重新选择</font>"; 78 document.getElementById("rsf").value=""; 79 b = false; 80 } 81 } 82 </script> 83 </head> 84 <body bgcolor=rgb(180,205,230)> 85 <div align="center"> 86 <form action="checkregister" method="post"> 87 <table border="1" cellpadding="0" cellspacing="0" name="mytable" bgcolor="white"> 88 <tr> 89 <td>用户ID:</td> 90 <td><input type="text" name="rid" id="rid" onblur="checkid(this)"></td> 91 <td><div id="userid"><font color="red">*<font></div></td> 92 </tr> 93 <tr> 94 <td>姓名:</td> 95 <td><input type="text" name="rname" id="rname" onblur="checkname(this)"></td> 96 <td><div id="username"><font color="red">*<font></div></td> 97 </tr> 98 <tr> 99 <td>性别:</td> 100 <td><input type="text" name="rsex" id="rsex" onblur="checksex(this)"></td> 101 <td><div id="usersex"><font color="red">*<font></div></td> 102 </tr> 103 <tr> 104 <td>年龄:</td> 105 <td><input type="text" name="rage" id="rage" onblur="checkage(this)"></td> 106 <td><div id="userage"><font color="red">*<font></div></td> 107 </tr> 108 <tr> 109 <td>地址:</td> 110 <td><input type="text" name="raddr" id="raddr" onblur="checkaddr(this)"></td> 111 <td><div id="useraddr"><font color="red">*<font></div></td> 112 </tr> 113 <tr> 114 <td>密码:</td> 115 <td><input type="password" name="rpass" id="rpass" onblur="checkpass(this)"></td> 116 <td><div id="userpass"><font color="red">*<font></div></td> 117 </tr> 118 <tr> 119 <td>身份:</td> 120 <td> 121 <select name="rsf" id="rsf" onblur="checksf(this)"> 122 <option value="学生" selected="seleected">学生</option> 123 <option value="教师" >教师</option> 124 </select> 125 </td> 126 <td><div id="usersf"><font color="red">*<font></div></td> 127 </tr> 128 </table> 129 </form> 130 <input type="submit" value="注册"> 131 <input type="reset" ><br/> 132 </div> 133 </body> 134 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head bgcolor=rgb(180,205,230)> 5 <title>注册</title> 6 <script type="text/javascript" > 7 function checkid(obj){ 8 var id=obj.value; 9 var pa=/^d{4}$/; 10 if(id.match(pa)==null){ 11 document.getElementById("userid").innerHTML="<font color='red'>请输入4位数字ID</font>"; 12 document.getElementById("rid").value=""; 13 }else{ 14 document.getElementById("userid").innerHTML="<font color='green'>ID合法</font>"; 15 } 16 } 17 function checkname(obj){ 18 var name = obj.value; 19 var pa=/^D{1,20}$/; 20 if(name.match(pa)==null){ 21 document.getElementById("username").innerHTML="<font color='red'>请输入用户名</font>"; 22 document.getElementById("rname").value=""; 23 b = false; 24 }else{ 25 document.getElementById("username").innerHTML="<font color='green'>用户名合法</font>"; 26 } 27 } 28 function checksex(obj){ 29 var sex=obj.value; 30 var pa=/^D$/; 31 if(sex.match(pa)==null){ 32 document.getElementById("usersex").innerHTML="<font color='red'>请输入性别</font>"; 33 document.getElementById("rsex").value=""; 34 }else{ 35 document.getElementById("usersex").innerHTML="<font color='green'>性别输入合法</font>"; 36 } 37 } 38 function checkage(obj){ 39 var age = obj.value; 40 var pa=/^d{1,3}/; 41 if(age.match(pa)==null){ 42 document.getElementById("userage").innerHTML="<font color='red'>请输入年龄</font>"; 43 document.getElementById("rage").value=""; 44 b = false; 45 }else{ 46 document.getElementById("userage").innerHTML="<font color='green'>年龄输入合法</font>"; 47 } 48 } 49 function checkaddr(obj){ 50 var raddr = obj.value; 51 var pa=/^D{1,20}/; 52 if(raddr.match(pa)==null){ 53 document.getElementById("useraddr").innerHTML="<font color='red'>请输入地址</font>"; 54 document.getElementById("raddr").value=""; 55 b = false; 56 }else{ 57 document.getElementById("useraddr").innerHTML="<font color='green'>地址输入合法</font>"; 58 } 59 } 60 function checkpass(obj){ 61 var rpass = obj.value; 62 var pa=/^d{6}/; 63 if(rpass.match(pa)==null){ 64 document.getElementById("userpass").innerHTML="<font color='red'>请输入密码</font>"; 65 document.getElementById("rpass").value=""; 66 b = false; 67 }else{ 68 document.getElementById("userpass").innerHTML="<font color='green'>密码输入合法</font>"; 69 } 70 } 71 function checksf(obj){ 72 var rsf = obj.value; 73 74 if((rsf=="学生")){ 75 document.getElementById("usersf").innerHTML="<font color='green'>已选择</font>"; 76 }else{ 77 document.getElementById("usersf").innerHTML="<font color='red'>请重新选择</font>"; 78 document.getElementById("rsf").value=""; 79 b = false; 80 } 81 } 82 </script> 83 </head> 84 <body bgcolor=rgb(180,205,230)> 85 <% 86 request.setCharacterEncoding("UTF-8"); 87 if(session.getAttribute("showname")!=null){ 88 %> 89 <div align="left"> 90 <form action="insertstu" method="post"> 91 <table border="1" cellpadding="0" cellspacing="0" name="mytable" bgcolor="white"> 92 <tr> 93 <td>用户ID:</td> 94 <td><input type="text" name="rid" id="rid" onblur="checkid(this)"></td> 95 <td><div id="userid"><font color="red">*<font></div></td> 96 </tr> 97 <tr> 98 <td>姓名:</td> 99 <td><input type="text" name="rname" id="rname" onblur="checkname(this)"></td> 100 <td><div id="username"><font color="red">*<font></div></td> 101 </tr> 102 <tr> 103 <td>性别:</td> 104 <td><input type="text" name="rsex" id="rsex" onblur="checksex(this)"></td> 105 <td><div id="usersex"><font color="red">*<font></div></td> 106 </tr> 107 <tr> 108 <td>年龄:</td> 109 <td><input type="text" name="rage" id="rage" onblur="checkage(this)"></td> 110 <td><div id="userage"><font color="red">*<font></div></td> 111 </tr> 112 <tr> 113 <td>地址:</td> 114 <td><input type="text" name="raddr" id="raddr" onblur="checkaddr(this)"></td> 115 <td><div id="useraddr"><font color="red">*<font></div></td> 116 </tr> 117 <tr> 118 <td>密码:</td> 119 <td><input type="password" name="rpass" id="rpass" onblur="checkpass(this)"></td> 120 <td><div id="userpass"><font color="red">*<font></div></td> 121 </tr> 122 <tr> 123 <td>身份:</td> 124 <td> 125 <select name="rsf" id="rsf" onblur="checksf(this)"> 126 <option value="学生" selected="seleected">学生</option> 127 </select> 128 </td> 129 <td><div id="usersf"><font color="red">*<font></div></td> 130 </tr> 131 </table> 132 133 </form> 134 <input type="submit" value="注册"> 135 <input type="reset" ><br/> 136 </div> 137 <% 138 }else{ 139 %> 140 <div align="right" class="fd"> 141 请先<a href="index.jsp">登录</a> 142 </div> 143 <% 144 } 145 %> 146 </body> 147 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>删除</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 13 <form action="deletestu" method="post"> 14 学生ID<input type="text" name="rid"><br/> 15 <input type="submit" value="删除"> 16 <input type="reset" ><br/> 17 </form> 18 <% 19 }else{ 20 %> 21 <div align="right" class="fd"> 22 请先<a href="index.jsp">登录</a> 23 </div> 24 <% 25 } 26 %> 27 </body> 28 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>注册</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 <form action="updatestu" method="post"> 13 要更改的学生ID<input type="text" name="rid"><br/> 14 <h4>请输入更改后的信息:</h4> 15 学生姓名:<input type="text" name="rname"><br/> 16 学生性别:<input type="text" name="rsex"><br/> 17 学生年龄:<input type="text" name="rage"><br/> 18 学生地址:<input type="text" name="raddress"><br/> 19 学生密码:<input type="text" name="rpass"><br/> 20 身份:<select name="rsf"> 21 <option value="学生" selected="seleected">学生</option> 22 </select><br/> 23 24 <input type="submit" value="确认更改"> 25 <input type="reset" ><br/> 26 </form> 27 <% 28 }else{ 29 %> 30 <div align="right" class="fd"> 31 请先<a href="index.jsp">登录</a> 32 </div> 33 <% 34 } 35 %> 36 </body> 37 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>查询</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 <form action="selectstu" method="post"> 13 学生ID<input type="text" name="rid"><br/> 14 <input type="submit" value="查询"> 15 <input type="reset" ><br/> 16 </form> 17 <% 18 }else{ 19 %> 20 <div align="right" class="fd"> 21 请先<a href="index.jsp">登录</a> 22 </div> 23 <% 24 } 25 %> 26 </body> 27 </html>
1 <%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%> 2 <!DOCTYPE html> 3 <html> 4 <head> 5 <title>jump</title> 6 </head> 7 <body bgcolor=rgb(180,205,230)> 8 <% 9 request.setCharacterEncoding("UTF-8"); 10 if(session.getAttribute("showname")!=null){ 11 %> 12 13 <div align="left" > 14 <table border="1" cellpadding="5" cellspacing="0" bgcolor="gray"> 15 <tr> 16 <td>ID:</td> 17 <td><%=session.getAttribute("id") %></td> 18 </tr> 19 <tr> 20 <td>姓名:</td> 21 <td><%=session.getAttribute("name") %></td> 22 </tr> 23 <tr> 24 <td>性别:</td> 25 <td><%=session.getAttribute("sex") %></td> 26 </tr> 27 <tr> 28 <td>年龄:</td> 29 <td><%=session.getAttribute("age") %></td> 30 </tr> 31 <tr> 32 <td>地址:</td> 33 <td><%=session.getAttribute("address") %></td> 34 </tr> 35 <tr> 36 <td>密码:</td> 37 <td><%=session.getAttribute("password") %></td> 38 </tr> 39 <tr> 40 <td>身份:</td> 41 <td><%=session.getAttribute("sf") %></td> 42 </tr> 43 44 </table> 45 </div> 46 <% 47 }else{ 48 %> 49 <div align="right" class="fd"> 50 请先<a href="index.jsp">登录</a> 51 </div> 52 <% 53 } 54 %> 55 </body> 56 </html>