开发者

How to redirect form a controller and get value in jsp

开发者 https://www.devze.com 2023-04-06 22:44 出处:网络
http://localhost:8080/LACASServer/message.jsp?forgotUser=Mail+has+been+sent+to+your+mail+address Here forgotUser is key of a map, that i set in a controller\'s method, which redirect to message.jsp,
http://localhost:8080/LACASServer/message.jsp?forgotUser=Mail+has+been+sent+to+your+mail+address

Here forgotUser is key of a map, that i set in a controller's method, which redirect to message.jsp, now how can i use it this map in message.jap to show value of that map. I am using jstl library

controler method is as:

@RequestMapping(value = "/forgotPWD",params="username", method = RequestMethod.POST)
            public String forgotPassword(@RequestParam(value = "username", required = false) String username,Map<String, Object> map) {
                System.out.println("forgotPasswordUser"+username);
                ResetPasswordLog resetPasswordLog;
                User forgotPasswordUser = usersService.findUser(username);
                map.put("forgotUser","Mail has been sent to your mail address");
                if(forgotPasswordUser==null){
                    return "redirect:/login.jsp?login_error=1";
                }
                else
                {   



                    Integer uid=forgotPasswordUser.getId();
                    resetPasswordLog=   usersService.setTempHash(uid);
                    String TEMPHASH= resetPasswordLog.getTempHash();
                    String url=Utility.serverURL+"forgot/index?uid="+uid+"&token="+TEMPHASH;
                    System.out.println(url);
                    System.out.println(Utility.mailResetSubject);
                    mailSender.sendMail(Utility.mailFrom,"romijain3186@gmail.com",Utility.mailResetSubject, url);
                    return "r开发者_运维问答edirect:/message.jsp";


                }

            }


You need your controller method (the one shown above) to specify the "view" itself (not use a redirect, as it currently does). So the return value should be a String that corresponds to the view name for message.jsp. You can then add the map to the model and it will be available in the JSP. E.g.

@RequestMapping(value = "/forgotPWD",params="username", method = RequestMethod.POST)
public String forgotPassword(@RequestParam(value = "username", required = false) String username,
         Map<String, Object> map, Model model) {
    [snip]
    map.put("forgotUser","Mail has been sent to your mail address");
    model.addAttribute("userMap", map);
    [snip]
    return "message.jsp"; // or just "message" depending on Spring settings
}

Then in your JSP access the map via JSTL: ${userMap.forgotUser}

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号