[英]Spring MVC Session: Expected Session attribute 'user', which already there in Session
我面对
org.springframework.web.HttpSessionRequiredException: Expected session attribute "Money"
以下是一系列步骤:
1)用户从控制器获取页面:Finance / MoneyCreation
@Controller
@RequestMapping("/Finance/*")
@SessionAttributes({ "Money", "MoneyForm"})
public class MoneyController {
@RequestMapping(value = "MoneyCreation", method = RequestMethod.GET)
public String openMoneyLandingPage(@ModelAttribute("Money") Money money,
Model model) {
model.addAttribute("MoneyForm", form);
return "/okonomi/okonomiregister";
}
在上面的控制器中,会话属性Money不在其他地方设置(这是必需的吗?。现在,我必须从UI中打开单击按钮的对话框,该对话框执行以下操作:
AjaxController:财务/创建/金钱
@Controller
@RequestMapping("/Finance/*")
@SessionAttributes({ "Money", "MoneyForm" })
public class AjaxMoneyController{
@RequestMapping(value = "create/money", method = RequestMethod.POST)
public String openDialogBox(@ModelAttribute("Money") User user, Model model) {
return "/commonProcess/dialog/MoneyDialog";
}
点击按钮; 我正面临:
org.springframework.web.HttpSessionRequiredException: Expected session attribute "Money"
我是否需要将Money设置在其他位置?
是的,您需要在引用该属性之前将其放入http会话中。
引用非常好的Spring文档(您也应该研究它!),您将看到一个示例阅读
if (!model.containsAttribute("site")) {
model.addAttribute("site", new PetSite());
}
“ site”是SessionAttribute(在您的情况下为“ money”)。
您需要在使用对象之前将其加载到会话中。 标准方法是使用@ModelAttribute
方法 :
@ModelAttribute("Money")
Money getMoney() {
return new Money(); //or however you create a default
}
在每次请求之前都会调用getMoney()
。
在用户界面中,我添加了转化ID,此问题已得到解决。
var convId = $('#formId').find('input[name="_CONV_ID"]').val();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.