1、阅读构建之法 现代软件工程(第三版)
2、观看JSP+Servlet+MySql+Tomcat+JDBC项目详细讲解
3、java代码修改
1、增加用户信息界面
package com.edu.entity;
public class Luser {
private String lname;
private String lpwd;
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getLpwd() {
return lpwd;
}
public void setLpwd(String lpwd) {
this.lpwd = lpwd;
}
public Luser(String lname, String lpwd) {
super();
this.lname = lname;
this.lpwd = lpwd;
}
public Luser() {
// TODO 自动生成的构造函数存根
}
}
2、(。。。只有信息查询功能)
package com.edu.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.edu.entity.DbHelper;
import com.edu.entity.Luser;
public class Luserdao {
public boolean login(Luser luser) {
Connection conn = DbHelper.getConnection();
String sql = "select * from uselogin where lname=?";
boolean flag = false;
PreparedStatement pst = null;
Luser lu = new Luser();
ResultSet rst = null;
try {
pst = conn.prepareStatement(sql);
pst.setString(1,luser.getLname());
rst = pst.executeQuery();
while(rst.next()) {
lu.setLname(rst.getString("lname"));
lu.setLpwd(rst.getString("lpwd"));
}
if(luser.getLpwd().equals(lu.getLpwd())) {
flag = true;
}
rst.close();
pst.close();
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
// TODO 自动生成的方法存根
return flag;
}
}
3、
package com.edu.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.edu.dao.Luserdao;
import com.edu.entity.Luser;
@WebServlet("/Loginuserservlet")
public class Loginuserservlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String lname = request.getParameter("lname");
String lpwd = request.getParameter("lpwd");
Luser luser = new Luser();
if((lname!=null) && (lpwd!=null)&&(lname!="")&&(lpwd!="")) {
luser.setLname(lname);
luser.setLpwd(lpwd);
Luserdao luserdao = new Luserdao();
if(luserdao.login(luser)) {
request.getRequestDispatcher("/Menu.jsp").forward(request, response);
}else {
request.getRequestDispatcher("/elogin.jsp").forward(request, response);
}
}else {
request.getRequestDispatcher("/userlogin.jsp").forward(request, response);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}