首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

怎么把JSP中声明的变量传给Action

2012-02-26 
如何把JSP中声明的变量传给Action我在JSP中声明了变量username如下:(ACEGI获取用户名)%SecurityContext c

如何把JSP中声明的变量传给Action
我在JSP中声明了变量username如下:(ACEGI获取用户名)
<%
 
  SecurityContext context=(SecurityContext)SecurityContextHolder.getContext();
  Authentication auth=context.getAuthentication();
  String username="";
  if(auth.getPrincipal() instanceof UserDetails){
  username=((UserDetails)auth.getPrincipal()).getUsername();

   
   
  } else{
  username=auth.getPrincipal().toString();
  }
%>


我现在需要把username传到action里,应该用什么样的方式?
或者是我可以在ACTION中直接调用ACEGI获取用户名的方法吗?我试了一下再ACTION中调用上面那段代码来获取用户名,结果是NULLPOINTEXCEPTION
请教高手指点

[解决办法]

探讨
引用:
我在jsp中加入 ServletActionContext.getRequest().getSession().setAttribute("name",username)
该JSP页面报错啊

问题就出在我在JSP中把username装进request.setAttribute;
在Action中用ServletActionContext.getRequest().getSession().getAttribute("login")
然后System.out.println(login)
系统打印的值为NULL
究竟是怎么回事啊?

热点排行