登录获取的是数据库里面的username和password,想实现登录跳转的界面只显示登录账号的数据库信息,目前显示的是数据库里面的全部信息
dao层:public List<Only> findAll();
daoimpl层: public List<Only> findAll() {
//使用JDBC操作数据库...
//1.定义sql
String sql = "select * from only";
List<Only> students = template.query(sql, new BeanPropertyRowMapper<Only>(Only.class));
return students;
}
service层: public List<Only> findAll();
serviceimpl层:public List<Only> findAll() {
//调用Dao完成查询
return dao.findAll();
servlet层:/获取条件查询参数
Map<String, String[]> condition = request.getParameterMap();
//2.调用service查询
OnlyService service = new OnlyServiceImpl();
PageBean<Only> pb = service.findUserByPage(currentPage,rows,condition);
System.out.println(pb);
//3.将PageBean存入request
request.setAttribute("pb",pb);
request.setAttribute("condition",condition);//将查询条件存入request
//4.转发到slist.jsp
request.getRequestDispatcher("/slist.jsp").forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
jsp页面:
<table border="1" class="table table-bordered table-hover">
<tr class="success">
<th class="yc">序号
姓名
事务
操作
<c:forEach items="${pb.list}" var="only" varStatus="s">
<td class="yc">${only.uid}
${only.username}
${only.event}
<a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/findStudentServlet?uid=${only.uid}">修改
</c:forEach>
登录servlet: Map<String, String[]> map = request.getParameterMap();
//4.封装Studentl对象
Studentl studentl = new Studentl();
try {
BeanUtils.populate(studentl,map);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
//5.调用Service查询
SlService service = new LoginServiceImpl();
Studentl SlStudent = service.Sl(studentl);
//6.判断是否登录成功
if(SlStudent != null){
//登录成功
//将用户存入session
session.setAttribute("studentl", SlStudent);
//跳转页面
response.sendRedirect(request.getContextPath()+"/findStudentByPageServlet");
}else{
//登录失败
//提示信息
request.setAttribute("login_msg","用户名或密码错误!");
//跳转登录页面
request.getRequestDispatcher("/stulogin.jsp").forward(request,response);
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}