我目前正在尝试将搜索条件属性保存到两个页面之间的会话:搜索页面和编辑页面。目标是保存三个变量:sYear、submission、collectionPeriod。我将这些添加到下面的“搜索”屏幕控制器中的会话中:
request.getSession().setAttribute("sYearSave", sYear);
request.getSession().setAttribute("submissionSave", submission);
request.getSession().setAttribute("collectionPeriodSave", collectionPeriod);
在编辑屏幕控制器中,我将布尔值设置isFromEditScreen
为true.
This is 所以我知道我来自编辑屏幕。我确实打印出变量,并且在编辑控制器屏幕中正确地获取了值。
request.getSession().setAttribute("isFromEditScreen", new Boolean(true));
sYearSave = (String)request.getSession().getAttribute("sYearSave");
collectionPeriodSave = (String)request.getSession().getAttribute("collectionPeriodSave");
submissionSave = (String)request.getSession().getAttribute("submissionSave");
但问题是当我使用后退按钮返回搜索屏幕时,搜索条件sYearSave, collectionPeriodSave, and submissionSave
值返回NULL.
由于某种原因,isFromEditScreen
布尔值工作正常并返回true.
它实际上进入语句但搜索条件返回null.
搜索控制器代码如下:
if (isFromEditScreen != null && isFromEditScreen == true) {
System.out.println("Inside isFromEditScreen ==== true");
sYear = (String)request.getSession().getAttribute("sYearSave");
collectionPeriod = (String)request.getSession().getAttribute("collectionPeriodSave");
submission = (String)request.getSession().getAttribute("submissionSave");
sYearSave = (String)request.getSession().getAttribute("sYearSave");
collectionPeriodSave = (String)request.getSession().getAttribute("collectionPeriodSave");
submissionSave = (String)request.getSession().getAttribute("submissionSave");
System.out.println("sYearSave ==== " + sYearSave);
System.out.println("submissionSave ==== " + submissionSave);
System.out.println("collectionPeriodSave ==== " + collectionPeriodSave);
System.out.println("isFromEditScreen set in else ==== " + isFromEditScreen);
}
任何帮助将不胜感激!