这个路径跳转不过去是什么原因啊
修改密码的时候如果旧密码错误就不能修改密码并且重新跳转到这也修改密码的 页面,但是确是跳不过来,试了几次旧密码错误修改密码都不能重新跳转到 这个页面来,但是如果旧密码不错改新密码 就是可以修改,而且也可以正常的跳转页面,这是什么问题啊
正在回答
看着同学的控制台有报错信息:
看看是否第二次跳转到这个修改密码界面的时候,被登录拦截器给拦截了呢?
建议同学打断点跟一下。
祝学习愉快。
package com.imooc.sm.controller;
import com.imooc.sm.entity.Staff;
import com.imooc.sm.service.SelfService;
import com.imooc.sm.service.StaffService;
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;
public void toLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect("login.jsp");
}
public void login(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
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");
}
}
public void logout(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
HttpSession session = request.getSession();
session.setAttribute("USER", null);
response.sendRedirect("toLogin.do");
}
public void main(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendRedirect("index.jsp");
}
// 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");
//在父窗口转向到logout.do的路径下
response.getWriter().print("<script type=\"text/javascript\">parent.location.href=\"logout.do\"</script>");
}
}
}
- 参与学习 人
- 提交作业 205 份
- 解答问题 4317 个
Java中非常实用的SSM整合开发内容,从Spring开始,到MyBaits的进阶内容,再到SpringMVC的应用,最后是SSM整合开发案例,逐步深入,助你成长为一名Java工程师!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星