正在回答
4回答
冲哥_
2019-02-22 10:03:36
package com.imooc.sm.controller; import com.imooc.sm.entity.Staff; import com.imooc.sm.service.SelfService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; @Controller("selfController") public class SelfController { @Autowired private SelfService selfService; // /toLogin.do public void toLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("login.jsp").forward(request,response); } // /login.do public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String account =request.getParameter("account"); String password = request.getParameter("password"); Staff staff = selfService.login(account,password); if(staff==null){ response.sendRedirect("toLogin.do"); }else{ HttpSession session = request.getSession(); session.setAttribute("USER",staff); response.sendRedirect("main.do"); } } // /logout.do public void logout(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); session.setAttribute("USER", null); response.sendRedirect("toLogin.do"); } // /main.do public void main(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("index.jsp").forward(request,response); } // /self/info.do public void info(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("../info.jsp").forward(request,response); } // /self/toChangePassword.do public void toChangePassword(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("../change_password.jsp").forward(request,response); } // /self/changePassword.do public void changePassword(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String password = request.getParameter("password"); String password1 = request.getParameter("password1"); HttpSession session = request.getSession(); Staff staff = (Staff)session.getAttribute("USER"); if(!staff.getPassword().equals(password)){ response.sendRedirect("toChangePassword.do"); }else{ selfService.changePassword(staff.getId(),password1); //response.sendRedirect("../logout.do"); response.getWriter().print("<script type=\"text/javascript\">parent.location.href=\"../logout.do\"</script>"); } } }
chrismorgen
2019-02-22 09:52:12
建议你将SelfController类中的代码粘贴一下,方便我们检查你的重定向是否有问题,这中情况下多数是重定向写的有问题哦,祝学习愉快~
冲哥_
2019-02-21 20:33:48
在浏览器里输入这个链接,因为设置了过滤器,所以跳到了http://localhost:8080/sm1/toLogin.do
这里。但是页面显示如图:
相似问题
登录后可查看更多问答,登录/注册
SSM主流框架入门与综合项目实战2018版
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星