问题描述
- 做一个简单的jsp登陆界面servlet报错
-
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)
}
解决方案
类名写错了吧
上面的类是LoginServlet ,而报的错是LogintServlet,多了一个t
时间: 2024-11-08 21:06:52