登录主程序

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<body>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
String driverName="com.mysql.jdbc.Driver";
String userName="root";
String userPwd="19961009smx8s";
String dbName="jrs";
String url1="jdbc:mysql://localhost:3306/"+dbName;
String url2="?user="+userName+"&password="+userPwd;
String url3="&useUnicode=true&characterEncoding=UTF-8";
String url=url1+url2+url3;
request.setCharacterEncoding("UTF-8");
try{
Class.forName(driverName);
conn=DriverManager.getConnection(url);
String Name=request.getParameter("RdName");
String Passwd=request.getParameter("RdPasswd");
String sql="select * from users where username=? and password=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,Name);
pstmt.setString(2,Passwd);
rs=pstmt.executeQuery();
if(rs.next()){
response.sendRedirect("ch03_11_loginCorrect.jsp");
}
else{
response.sendRedirect("fail.jsp"); } }
catch(Exception e){ }
finally {
if(rs!=null) {rs.close();}
if(pstmt!=null) {pstmt.close();}
if(conn!=null) {conn.close();}
}

%>
</body>
</html>

posted on 2017-10-20 20:04  3r3r3www  阅读(211)  评论(0编辑  收藏  举报

导航