基于servlet登录验证
1、在建立项目工程之前,需要先将mysql 数据库连接桥放入tomcat的lib文件夹中:
2、建立数据库:
数据库名为:web_homework
表名为: users
表结构为:
3、在项目的src文件中新建文件包model2,在包中新建java类:login_servlet.java,其中添加代码如下:
package model2;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class login_servlet extends HttpServlet {
Dbhelper db = null;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doPost(req, resp);
try {
db = new Dbhelper();
} catch (Exception e1) {