关于struts2的SessionAware的传值问题
SurveryAction.java
package com.njfu.surveypark.struts2.action; import java.util.List; import java.util.Map; import javax.annotation.Resource; import org.apache.struts2.interceptor.SessionAware; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import com.njfu.surveypark.model.Survey; import com.njfu.surveypark.model.User; import com.njfu.surveypark.service.SurveyService; /** * SurveyAction */ @Controller @Scope("prototype") public class SurveyAction extends BaseAction<Survey> implements SessionAware{ private static final long serialVersionUID = 587149269950475258L; //注入SurveyService @Resource private SurveyService surveyService; //调查集合 private List<Survey> mySurveys; //接受sessionMap private Map<String, Object> sessionMap; public List<Survey> getMySurveys() { return mySurveys; } public void setMySurveys(List<Survey> mySurveys) { this.mySurveys = mySurveys; } /** * 查询我的调查列表 */ public String mySurveys(){ User user= (User) sessionMap.get("User"); System.out.print(user); this.mySurveys = surveyService.findMySurveys(user); return "mySurveyListPage"; } /** * 新建调查列表 */ public String newSurvey(){ User user= (User) sessionMap.get("User"); System.out.print(user); this.model = surveyService.newSurvey(user); return "designSurveyPage"; } @Override public void setSession(Map<String, Object> arg0) { this.sessionMap = arg0; } }
System.out.print(user);控制开打印的是null
null Hibernate: insert into surveys (title, pretext, nexttext, donetext, exittext, createtime, userid) values (?, ?, ?, ?, ?, ?, ?) Hibernate: insert into pages (title, description, surveyid) values (?, ?, ?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚发完贴,突然就找到原因了 User user= (User) sessionMap.get("User");括号中的(User),应该小写的