[英]How to send data from controller to jsp in spring 3.0
我正在嘗試將數據發送到jsp,但無法正常工作
public class LoginPageController extends SimpleFormController
{
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws ServletException
{
Loginpage lcmd=(Loginpage)command;
System.out.println("This is LOGIN PAGE");
System.out.println(lcmd.getUserName());
System.out.println(lcmd.getPassWord());
request.setAttribute("MSG","Thank u"); //This code not doing anything.
return new ModelAndView(new RedirectView("Login.jlc"));
}
}
您正在更改request
對象,這實際上不會執行任何操作。
您需要為Model添加一個變量。 因此,您可以執行以下操作:
代替:
request.setAttribute("MSG","Thank u"); //This code not doing anything.
return new ModelAndView(new RedirectView("Login.jlc"));
嘗試這個:
Map<String, Object> model = new HashMap<String, Object>();
model.put("MSG", "Thank u");
return new ModelAndView(new RedirectView("Login.jlc"), model); // <-- notice this
如果將它們添加到model
圖中,這將使您可以通過表達式${model.MSG}
和其他表達式來訪問"Thank u"
值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.