qq_35170693 2016-06-22 06:22 采纳率: 0%
浏览 1151

Mycelipse连接成功了MySQL,页面却不跳转

下面有三个代码,第一个是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>
  • 写回答

4条回答 默认 最新

  • 我说假如 2016-06-22 06:31
    关注

    最好别在页面上做这些处理。这样还不如直接写个Servlet。

    而且,你的user,你打印看看有没有东西。。。

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记