2 zero kill zero_kill 于 2015.06.24 23:33 提问

做一个简单的jsp登陆界面servlet报错
jsp

package com.demo;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
Connection dbconn = null;

public void init() {
    String driver = "com.mysql.jdbc.Driver";  //MySQL驱动
    String dburl = "jdbc:mysql://127.0.0.1:3306/wuliu";
    String username = "root";
    String password = "";
    try {
        Class.forName(driver); // 加载驱动程序
        dbconn = DriverManager.getConnection(dburl, username, password);// 创建连接对象
    } catch (ClassNotFoundException e1) {
        System.out.println(e1);
    } catch (SQLException e2) {
    }
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String username = request.getParameter("username");
    //String psw = request.getParameter("password");
    try {
        String sql = "select * from user where name = ?";
        PreparedStatement pstmt =dbconn.prepareStatement(sql);
        pstmt.setString( 1,username);//绑定数据
        ResultSet rst =pstmt.executeQuery();
        if (rst.next()) {
            //String databasepassword = rst.getString("password");
              // if(databasepassword.equals(password))  
            response.sendRedirect("/1-1-login/success.jsp");
        } else {
            response.sendRedirect("/1-1-login/error.jsp");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
public void destroy() {
    try {
        dbconn.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}![图片说明](http://img.ask.csdn.net/upload/201506/24/1435159996_35283.png)

}

2个回答

danielinbiti
danielinbiti   Ds   Rxr 2015.06.24 23:44
已采纳

类名写错了吧
上面的类是LoginServlet ,而报的错是LogintServlet,多了一个t

danielinbiti
danielinbiti 回复zero_kill: 看看浏览器上这个空白页面的路径是什么。
2 年多之前 回复
zero_kill
zero_kill 谢谢,听了您的建议,搜的web.xml配错了,改了之后,用户名密码输入正确后,却不能跳转到我所需要的界面,他就跳转到一个空白界面,这是为什么
2 年多之前 回复
zero_kill
zero_kill   2015.06.24 23:36

图片说明

zero_kill
zero_kill 回复weixin_29288785: 并没有用啊
2 年多之前 回复
weixin_29288785
weixin_29288785 百度一凡
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片