java web期末很low的考核程序,登录验证和注册验证! - ^Rourou
java web期末很low的考核程序,登录验证和注册验证!
登录验证:Logincheck.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><title>登录成功页面</title></head>
<body >
<% ResultSet rs=null;
String driverName="com.mysql.jdbc.Driver";
String userName="root";//数据库用户名
String userPwd="123456";//密码
String dbName="students";//数据库名
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=utf8";
String url=url1+url2+url3;
System.out.println(url);
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(url);
request.setCharacterEncoding("utf8");//避免乱码,设置字符编码
String usernumber=request.getParameter("usernumber");
String password=request.getParameter("password");
String sql="select * from stu_info where usernumber=? and password=?";
PreparedStatement ps= conn.prepareStatement(sql);
ps.setString(1,usernumber);
ps.setString(2,password);
rs=ps.executeQuery();
if(rs.next()){ response.sendRedirect("doLogin.jsp");%><% }
else{%> 登录失败!<a href="Login.jsp">点击返回登录页面检查或进行注册!</a><br><%}
if(rs!=null){rs.close();}
if(ps!=null){ps.close();}
if(conn!=null){conn.close();}
%>
</body>
</html>
注册验证:insert.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<html>
<body>
<%
request.setCharacterEncoding("utf-8");//避免乱码,设置字符编码
String driverName="com.mysql.jdbc.Driver";
String userName="root";//数据库用户名
String userPwd="123456";//密码
String dbName="students";//数据库名
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=utf8";
String url=url1+url2+url3;
System.out.println(url);
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(url);
String usernumber= request.getParameter("usernumber");
String username=request.getParameter("username");
String password=request.getParameter("password");
String age=request.getParameter("age");
String sql="Insert into stu_info(usernumber,username,password,age) values(?,?,?,?)";
PreparedStatement ps= conn.prepareStatement(sql);
ps.setString(1,usernumber);
ps.setString(2,username);
ps.setString(3,password);
ps.setString(4,age);
// ps.setString(5,sdept);
int n = ps.executeUpdate();
if(n==1){
response.sendRedirect("zhuceSuccess.jsp");
}
else{%>alert("error!");<%}
if(ps!=null){ ps.close();}
if(conn!=null){conn.close();}
%>
</body>
</html>
posted on
2017-12-18 21:59
^Rourou
阅读(165)
评论(0)
编辑
收藏
举报
以上是 java web期末很low的考核程序,登录验证和注册验证! - ^Rourou 的全部内容, 来源链接: utcz.com/z/391190.html