日期:2014-05-18  浏览次数:20736 次

紧急求助action如何获取session
	@RequestMapping(value = "/update")
@ResponseBody
public String update(HttpServletRequest req, RulInfo rul)
throws IOException {

try {
if (!isEmpty(rul.getmName())) {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss ");
rul.setrTime(df.format(new Date()));
rul.setwUpdated("2");
rulService.update(rul);
map.put("success", true);
map.put("msg", "信息保存成功");
}
} catch (Exception e) {
map.put("success", false);
map.put("msg", "提示:" + e.getMessage());
e.printStackTrace();
}
return toJson(map);

}


上面是一段Action更新的代码,该如何获取当前登录的用户名。
前面已经在LoginAction里设置过session了
		if (checkUsrId) {
req.getRequestDispatcher("/index.jsp").forward(req, resp);
return null;
} else {
req.getSession().setAttribute("usrInfo", usr);
}
return "welcome";

------解决方案--------------------
req.getSession().getAttribute("usrInfo");
------解决方案--------------------
HttpSession session = request.getSeeion();
------解决方案--------------------
在上面的那段代码里往session中放入信息
req.getSession().setAttribute("usrInfo",你要存入的信息);