package LoginServlet;import org.hz.dbc.*;import java.io.*;import java.sql.*;
import javax.servlet.*;import javax.servlet.http.*;
public class Check extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
PreparedStatement ps = null;
ResultSet rs = null;
request.setCharacterEncoding("GBK");
response.setContentType("text/html");
//获取账号密码
String name = request.getParameter("name");
String pass = request.getParameter("password");
//获取数据库操作
databaseConnection dbc = new databaseConnection();
String sql = "select UPASS from users where UNAME='?'";
try {
ps=dbc.getConnection().prepareStatement(sql);
ps.setString(1, name);
rs=ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(rs.next()){
//保存密码,与输入的密码进行匹配,
String p = rs.getString(1);
if(pass.equals(p)){
request.setAttribute("name", "name");
request.getRequestDispatcher("wel").forward(request, response);
}}else{
//不匹配则跳回
response.sendRedirect("Login.java");}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try{
dbc.getConnection().close();}catch(Exception e){e.printStackTrace();}}}
}
import javax.servlet.*;import javax.servlet.http.*;
public class Check extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
PreparedStatement ps = null;
ResultSet rs = null;
request.setCharacterEncoding("GBK");
response.setContentType("text/html");
//获取账号密码
String name = request.getParameter("name");
String pass = request.getParameter("password");
//获取数据库操作
databaseConnection dbc = new databaseConnection();
String sql = "select UPASS from users where UNAME='?'";
try {
ps=dbc.getConnection().prepareStatement(sql);
ps.setString(1, name);
rs=ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
}
try {
if(rs.next()){
//保存密码,与输入的密码进行匹配,
String p = rs.getString(1);
if(pass.equals(p)){
request.setAttribute("name", "name");
request.getRequestDispatcher("wel").forward(request, response);
}}else{
//不匹配则跳回
response.sendRedirect("Login.java");}
} catch (SQLException e) {
e.printStackTrace();
}finally{
try{
dbc.getConnection().close();}catch(Exception e){e.printStackTrace();}}}
}