<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>用户登录</title> <head> </head> <body> <p><label></label> </p> <form id="form1" name="form1" method="post" action=""> <p align="center"><strong>用户登录 </strong></p> </form> <p> </p> <form action="NewFile.jsp" method="post"> <table width="252" border="1" align="center"> <tr> <td width="72"><strong>用户名:</strong></td> <td width="164"><input name="num" type="text" /></td> </tr> <tr> <td><strong>密码:</strong></td> <td><input name="userpassword" type="password" /></td>//建立表格显示登录界面 </tr> <tr> <td> </td> <td><a href="NewFile.jsp" onclick="link"><input type="submit" name="submit" value="登录" ></a></td>//设置登录的按钮跳转界面 </tr> </table> </form> </body> </html>
<%@ page contentType = "text/html; charset=utf-8" import = "java.sql.*" errorPage = "error.jsp" %> <html> <head> </head> <body> <div style=text-align:center> <% String num = request.getParameter("num"); session.setAttribute("username",num); String userpassword = request.getParameter("userpassword"); Class.forName("com.mysql.jdbc.Driver"); Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","20153246");//登录JDBC链接数据库 Statement stmt = connect.createStatement();//从数据库里面取东西对比 String sql = "select * from user where name='"+num+"'and userpassword='"+userpassword+"'"; ResultSet i = stmt.executeQuery(sql); if(i.next()) { response.setHeader("refresh","1;url = NewFile1.html"); } else { out.println(i.next()+"ff"); out.println("<script language = 'javaScript'> alert('密码错误,请重新输入用户名!');</script>"); response.setHeader("refresh","1;url = NewFile.html"); } stmt.close(); connect.close(); %> </div> </body> <html>
<html> <!DOCTYPE html> <html lang="en" class="no-js"> <head> <meta charset="utf-8"> <title>登录(Login)</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <!-- CSS --> <link rel="stylesheet" href="assets/css/reset.css"> <link rel="stylesheet" href="assets/css/supersized.css"> <link rel="stylesheet" href="assets/css/style.css"> <!-- HTML5 shim, for IE6-8 support of HTML5 elements --> <!--[if lt IE 9]> <script src="assets/js/html5.js"></script> <![endif]--> </head> <body> <div class="page-container"> <script language = 'javaScript'> alert('成功登录界面!!!');</script> </div> <!-- Javascript --> <script src="assets/js/jquery-1.8.2.min.js" ></script> <script src="assets/js/supersized.3.2.7.min.js" ></script> <script src="assets/js/supersized-init.js" ></script> <script src="assets/js/scripts.js" ></script> </body> <div style="text-align:center;"> </div> </html>