<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
用户登陆
登陆 ID:
登陆密码:
<%!
public static final String DBDRIVER = "com.mysql.jdbc.Driver" ;
public static final String userName = "root"; //登录的用户名
public static final String userPasswd = "root"; //登录mysql密码
public static final String dbName = "test"; //数据库名
public static final String tableName="form1"; //表名
public static final String DBURL = "jdbc:mysql://localhost:3306/"+dbName+"?user="+userName+"&password="+userPasswd;
%>
<%
Connection conn = null ;
PreparedStatement pstmt = null ;
ResultSet rs = null ;
boolean flag = false ; // 表示登陆成功或失败的标记
%>
<%
String userid = request.getParameter("username") ; // 接收表单参数
String password = request.getParameter("password") ; // 接收表单参数
try{
Class.forName(DBDRIVER) ;
conn = DriverManager.getConnection(DBURL) ;
String sql = "SELECT userid,password FROM tuser WHERE userid=? AND password=?" ;
pstmt = conn.prepareStatement(sql) ;
pstmt.setString(1,userid) ;
pstmt.setString(2,password) ;
rs = pstmt.executeQuery() ;
while(rs.next()){
// 如果有内容,则此处执行,表示查询出来,合法用户
flag = true ;
}
}catch(Exception e){
}finally{
try{
conn.close() ; // 连接一关闭,所有的操作都将关闭
}catch(Exception e){}
}
%>
<%
if(flag){ // 登陆成功,应该跳转到success.jsp
%>
<%
}else{ // 登陆失败,跳转到failure.jsp
%>
<%
}
%>
声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com