2015-03-13 94 views
0

我有一個簡單的J2EE應用程序和Spring。 現在我想從Java控制器調用另一個頁面。例如,我在registrazione.jsp中,點擊一個按鈕,然後在registrazioneController.java中調用一個方法。如何從java控制器調用JSP

現在我想從registrazioneController.java,調用另一個頁面,例如

針對home.jsp,我想傳遞任何參數的獲取。

有可能嗎?

這是當我按一下按鈕

registrazioenControlle.java

public ModelAndView internalLoadPage(HttpServletRequest request, HttpServletResponse response, Map model) throws Exception 
    { 

     //to do 
     //call another page for example home.html 
     request.getRequestDispatcher("home.jsp").forward(request, response); 
     return new ModelAndView("home", model); 
    } 

我,我用嘗試使用此代碼,但沒有找到方法。

+0

的[春季MVC控制器重定向響應使用代替URL參數]可能重複(http://stackoverflow.com/questions/2500592/spring-mvc-controller-redirect-using-url-parameters-in-in-response) – 2015-03-13 15:32:34

+0

你想從控制器重定向。 http://stackoverflow.com/questions/2500592/sp​​ring-mvc-controller-redirect-using-url-parameters-instead-of-in-response – 2015-03-13 15:33:03

+0

你總是可以在你的控制器中使用reidrect – Nb12se 2015-04-26 03:00:25

回答

1

除了註釋中提供的答案之外,如果您想在重定向時向URL附加參數,還可以使用RedirectAttributes和addAttribute方法。這也會給你addFlashAttribute這將存儲在閃光範圍內的屬性,這將使其可用於重定向頁面。您也可以返回一個簡單的字符串作爲視圖名稱,例如像

public String internalLoadPage(RedirectAttributes redirectAttributes) throws Exception 
    { 
     redirectAttributes.addAttribute("paramterKey", "parameter"); 
     redirectAttributes.addFlashAttribute("pageKey", "pageAttribute"); 
     return "redirect:/home"; 
    } 

此假定視圖後綴被配置成查看解析器配置