Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在spring控制器方法之间发送参数_Java_Spring_Spring Mvc - Fatal编程技术网

Java 如何在spring控制器方法之间发送参数

Java 如何在spring控制器方法之间发送参数,java,spring,spring-mvc,Java,Spring,Spring Mvc,我有一个resetPassword.jsp表单,它发布到resetPassword方法,请求被重定向到updateNewPassword方法,如下所示 我使用jdk 7和spring MVC 4 @RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView resetPassword(HttpServletRequest request, HttpServletResponse re

我有一个resetPassword.jsp表单,它发布到resetPassword方法,请求被重定向到updateNewPassword方法,如下所示

我使用jdk 7和spring MVC 4

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView resetPassword(HttpServletRequest request, HttpServletResponse response) throws IOException,
        ServletException {
    getCurrentRequestProperties().put(CurrentRequestProperties.IS_VALID_REQUEST, true);
    ModelAndView mav = new ModelAndView();
    String hStrCallback = request.getParameter("hString");
    UserSecurityQuestions qRecord;
    if (qRecord.equalsAnswer(1, ans1) && qRecord.equalsAnswer(2, ans2)) {
            RequestDispatcher rd = request.getRequestDispatcher("/updateNewPassword.do");
            rd.forward(request, response);
            mav.setViewName("updateNewPassword.do");
    }
    mav.addObject("notimeout", true);
    return mav;
}

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView updateNewPassword(HttpServletRequest request, HttpServletResponse response) throws IOException,
        ServletException {
    getCurrentRequestProperties().put(CurrentRequestProperties.IS_VALID_REQUEST, true);
    ModelAndView mav = new ModelAndView();
    String hString = request.getParameter("hString");
     String newPassword = request.getParameter("newPassword");
    String confirmPassword = request.getParameter("confirmPassword");
    if (StringUtils.isNotEmpty(newPassword) || StringUtils.isNotEmpty(confirmPassword)) {
        UserSecurityQuestions qRecord = api.search.query(UserSecurityQuestions.class,
                api.search.property("hashString").eq(hString)).first();
        if (qRecord != null && !qRecord.isValidRequest()) {
            mav.addObject("failedMessage", "forgot.url.expired");
        } else 
        {
          // updates the password
         }
        } else {
        mav.addObject("hString", hString);
        mav.addObject("notimeout", true);
    }
    return mav;
}
步骤1:这是工作流程,当为用户重置密码时,电子邮件将作为bwlow发送 https://dc-rpall/CP/resetPassword.do?hStr=50585030a9ae6cb4 当用户单击URL时,用户将获得带有securityQuestions的resetPassword.jsp

步骤2:一旦用户回答了安全问题,就会将用户重定向到updatedPassword.jsp请求在此步骤中从resetPassword方法转到updateNewPassword方法,并且可以在此处访问hs字符串

步骤3:当用户在updatedPassword.jsp上更新密码并提交它时,请求转到updateNewPassword方法,但在这一步中,即使我在updatedPassword中将hString添加到mav对象中,我仍将hString设为null


有人能帮助我如何在步骤3中检索hString吗?

您得到的hString为null,因为当请求到达updateNewPassword时,它是一个新请求,并且没有hString作为请求参数。因为我将它作为mav.addObjecthString,hString添加到ModelAndView中;它不是应该在下一个请求中可用吗?但是您正在updateNewPassword中设置mav中的hString,这是第三步,您需要在resetPassword中进行设置。在第二步中,请求从resetPassword重定向到updatenewPassword,并且if StringUtils.isNotEmptynewPassword | | | StringUtils.isNotEmptyconfirmPassword条件在updatenewPassword中为false,因此请求转到else块并在mav中设置hs字符串。在第三步中,如果StringUtils.isNotEmptynewPassword | | | | StringUtils.isNotEmptyconfirmPassword条件为true,则请求再次转到updateNewPassword,它将更新密码。您传递的url是否与上面附加的url完全相同?在url中似乎是hStr,但您正在尝试检索hString