2

我正在尝试将数据发送到 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"));
   }
}
4

1 回答 1

1

您正在更改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

如果您将它们添加到地图中,这将使您能够"Thank u"通过表达式和其他值访问该值。${model.MSG}model

于 2013-05-23T18:11:29.183 回答