类型转换问题
1)在LoginAction中:
//用户登录成功后,取角色
int role=loginService.getRole();
ActionContext.getContext().getSession().put("Role", "role");
2)在AddUserAction中:
//取登录者角色
String s = (String)ActionContext.getContext().getSession().get("role");
int role = Integer.valueOf(s).intValue();
或int role = Integer.parseInt(s);
提示如下错误:
javax.servlet.ServletException: java.lang.NumberFormatException: For input string: "role"
然后,将1)中的“role”去掉引号,提示错误为:
javax.servlet.ServletException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
想在role为int型的情况下,完成存和取的操作,有办法吗?网上搜索了好久,没找到正解