我有一個redirect的問題。我正在開發一個web應用程序,在spring mvc中使用ModelAndView來在新頁面或主頁上進行forword。如何重定向提交表單?
1.當我提交表單modelAndView轉發到新頁面但url沒有變化。
public ModelAndView processForm(@ModelAttribute("registerForm")EmpRegistrationForm registerForm,HttpServletRequest request, HttpServletResponse response, ModelMap model)
{
registerForm = (EmpRegistrationForm) model.get("registerForm");
ModelAndView model1= new ModelAndView(GlobalConstants.HOME_PAGE);
model=super.execute(model);
EmpRegisterWorker worker=new EmpRegisterWorker();
boolean status=worker.validateUser(registerForm);
if(status)
{
return new ModelAndView(GlobalConstants.HOME_PAGE);
}
else
{
return new ModelAndView(GlobalConstants.ERROR_PAGE);
}
2.如果我刷新該頁面,表單會提交兩次,這是不可取的。
3.我必須點擊兩次或三次才能返回到新頁面。
4,我已經創造GlobalConstants類,我聲明的所有形式,如:
public static final String ERRORPAGE="errorPage";
public static final String HOME_PAGE="homePage";
有什麼辦法來解決這個問題。
你想用彈簧API重定向到網頁? – Vijay