gpt4 book ai didi

java - spring 3.0如何从controller向jsp发送数据

转载 作者:行者123 更新时间:2023-11-30 11:33:15 25 4
gpt4 key购买 nike

我正在尝试将数据发送到 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对象,那确实什么都不做。

您想要的是向模型 添加一个变量。因此,您可以这样做:

代替:

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 map 。

关于java - spring 3.0如何从controller向jsp发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16176874/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com