下面有三个代码,第一个是connect数据库的,第二个是获取验证用户名和密码的Java,第三个是跳转的页面,就是在第三个的login卡住了跳转不了我想要的页面,不知道是数据库的验证出了问题还是其他问题
package com.zuoyeshangjiaoxitong.connect;
import java.sql.Connection;
import java.sql.DriverManager;
public class connect {
public Connection getConnect(){
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/aaa";
String user = "root";
String password = "1234";
Connection conn = DriverManager.getConnection(url, user, password);
//System.out.print(conn.getMetaData().getURL());
return conn;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
}
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import beans.Customer;
import beans.CustomerEdit;
import beans.ShoppingCartBookEdit;
import beans.ShoppingCartEdit;
import com.zuoyeshangjiaoxitong.connect.connect;
import com.zuoyeshangjiaoxitong.model.userTable;
public class userservice {
private Connection conn;
private PreparedStatement pstmt;
public userservice() {
conn = new connect().getConnect();
}
public boolean isLogin(String stuId,String userpassword,int utype) {
try {
pstmt=conn.prepareStatement("select * from usertable where stuId="+stuId+" and password="+userpassword+" and utypeid="+utype+"");
pstmt.setString(1, stuId);
pstmt.setString(2, userpassword);
pstmt.setInt(3, utype);
ResultSet rs = pstmt.executeQuery();
//System.out.println(" " + stuId+ " " + userpassword + " " + utype);
} catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}
}
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>欢迎登陆学生作业管理系统</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<jsp:useBean id="user" class="com.zuoyeshangjiaoxitong.model.userTable"></jsp:useBean>
<jsp:setProperty property="*" name="user" />
<jsp:useBean id="logincheck"
class="com.zuoyeshangjiaoxitong.servlet.userservice"></jsp:useBean>
<%
if (logincheck.isLogin(user.getStuId(),
user.getUser_password(), user.getUser_type_id())) {
session.setAttribute("userpassword", user.getUser_password());
session.setAttribute("utype", user.getUser_type_id());
session.setAttribute("userid", user.getUser_id());
session.setAttribute("stuId",user.getStuId());
if (user.getUser_type_id() == 0)
response.sendRedirect("teacher.jsp");
if (user.getUser_type_id() == 1)
response.sendRedirect("student.jsp");
}
%>
</body>
</html>