如何打开jsp页面而不管路径变量是否通过?

时间:2016-10-14 06:30:12

标签: spring jsp spring-mvc

这是我的emaillogin.jsp的控制器方法

    @RequestMapping(value = "/quickstart/email")

    public String viewQuickStartEmailForm(@ModelAttribute(value = "quickbean") 
    QuickStartBean quickbean,BindingResult result,Model model) {

        try {       

email=quickbean.getEmail();
model.addAttribute("email", email);

model.addAttribute("quickstartdatabean",new QuickStartBean() );


        } catch (Exception e) {
            e.printStackTrace();
        }

        return "quickstart/emaillogin";
    }

这是我的控制器方法,用于页面邀请.jsp

@RequestMapping(value = "/quickstart/invite" )

    public String viewQuickStartInviteForm(@ModelAttribute(value = "quickbean") 
    QuickStartBean quickbean,BindingResult result,Model model {

        try {                   
inviteEmailEncrypted=getMD5(quickbean.getInviteeEmail());
address="http://localhost:8090/QuickStartConsulting/quickstart/email?key=";
model.addAttribute("inviteEmailEncrypted", inviteEmailEncrypted);
model.addAttribute("address", address);     
model.addAttribute("quickstartdatabean",new QuickStartBean() );
        } catch (Exception e) {
            e.printStackTrace();
        }


        return "quickstart/invitation";
    }

仅生成网址的invitation.jsp

http://localhost:8090/QuickStartConsulting/quickstart/email?key=d58e3582afa99040e27b92b13c8f2280

现在我想在用户传递上述网址时打开我的emailogin.jsp页面。 Emaillogin页面是我的第一页。 邀请页面和emaillogin页面未通过操作连接。 我该怎么办?

1 个答案:

答案 0 :(得分:0)

使用redirect返回其他网址

@RequestMapping(value = "/quickstart/invite" )
public ModelAndView viewQuickStartEmailForm(@ModelAttribute(value = "quickbean")  QuickStartBean quickbean,BindingResult result,Model model) {
     inviteEmailEncrypted=getMD5(quickbean.getInviteeEmail());
     address="http://localhost:8090/QuickStartConsulting/quickstart/email?key="+inviteEmailEncrypted;
     return new ModelAndView("redirect:/"+address);
}

另一个选择是使用 FlashAttributes