今天完成内容:
开发家庭小账本:登录
1.编写代码
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) {
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);
}
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
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;
}
遇到问题:
无
明日目标:
学习Android studio的开发