`
咖啡仔
  • 浏览: 42057 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

struts2的拦截器的getInvocationContext()和使用ActionContext.getContext()有什么不同?

    博客分类:
  • java
阅读更多
struts2的拦截器的intercept方法中使用invocation.getInvocationContext()和使用ActionContext.getContext()有什么不同?


ActionContext.getContext().getsession().put("test","123");


  public String intercept(ActionInvocation invocation) 
   {ActionContext ac = invocation.getInvocationContext();
  String s=(String)ac.getsession.get("test");

  }
s为null的

相反使用
 public String intercept(ActionInvocation invocation) 
 { 
    ActionContext ac = invocation.getInvocationContext();
    ac.getSession().put("test","123");
  }


  在
 
  ActionContext actionContext = ActionContext.getContext(); 
   Map session= actionContext.getSession();
   String s2=(String)session.get("test");

这里的s2就有值了,在拦截器也有值。

有什么不同的?
0
4
分享到:
评论

相关推荐

    Struts2_TypeConvertion

    这种方式主要是利用了...B.Map session=(Map)ActionContext.getContext().get(ActionContext.SESSION); 得到这个SessionMap之后我们就可以对session进行读写了,如果我们想得到原始的HttpSession可以首先

    struts2-junit-plugin-2.1.8.jar

    可解决java.lang.NoSuchMethodError: com.opensymphony.xwork2.ActionContext.get(Ljava/lang/Object;)Ljava/lang/Object; java.lang.ClassNotFoundException: com.opensymphony.xwork2.util.TextUtils struts2.1.8...

    基于struts2注册登录ActionContext.zip

    struts2大量使用拦截器来处理请求,从而允许与业务逻辑控制器 与 servlet-api分离,避免了侵入性(所谓侵入性就是指的这个架构设计出来的部件对系统的影响范围,标签库几乎可以完全替代JSTL的标签库,并且 struts2.x...

    struts2验证码完整实例

    通过ActionContext.getContext().getSession().put("random", randomNum.getRandomCode())将数字存放到session当中 2、当你登录时候,提交的输入框中的验证码和session中存放的验证码比较,如果一样,则通过,不一样,则...

    struts2OGNL表达式ActionContext及valuesStack.pdf

    struts2OGNL表达式ActionContext及valuesStack.pdf

    Java Struts 实现拦截器

    Struts2的处理流程: • 客户端产生一个HttpServletRequest的请求,该请求被提交到一系列的标准过滤器(Filter)组建链中(如ActionContextCleanUp:它主要是清理当前线程的ActionContext、Dispatcher,...

    JS客户端RSA加密,Java服务端解密

    ActionContext.getContext().put("exponent", new String(Hex.encodeHex(publicKey.getPublicExponent().toByteArray()))); // 页面里,Javascript对明文进行加密: 09 var modulus = $('#hid_modulus').val(); var...

    Struts2实战总结

    1:在action中定义的变量,在jsp页面中显示用:变量名" /> ...Map session = ActionContext.getContext().getSession(); HttpServletRequest request = ServletActionContext.getRequest (); 设置它们的值的方法

    struts2中范围对象的操作

    ActionContext actionContext=ActionContext.getContext(); Object obj=actionContext.get("objName");----Object obj=request.getAttribute("objName"); actionContext.put("objName",objName);---request....

    ActionContext介绍(在Struts2中)

    在Web应用程序开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话 (Session)的一些信息, 甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应...

    Struts2 in action中文版

    4.3 研究内建的Struts 2拦截器 67 4.3.1 工具拦截器 67 4.3.2 数据转移拦截器 67 4.3.3 工作流拦截器 69 4.3.4 其他拦截器 72 4.3.5 内建的拦截器栈 73 4.4 声明拦截器 74 4.4.1 声明独立的拦截器和拦截器栈 74 ...

    struts2中的ActionContext与ognl

    NULL 博文链接:https://lijiejava.iteye.com/blog/628636

    stuts2.2_API文档

    org.apache.struts2.ServletActionContext (implements org.apache.struts2.StrutsStatics) org.apache.struts2.RequestUtils org.apache.struts2.StrutsConstants java.lang.Throwable (implements java.io....

    Struts2通过使用ActionContext类获取request和response对象

    NULL 博文链接:https://zhouhaitao.iteye.com/blog/1126042

    struts2文件上传,与struts2-xml校验

    System.out.println("上下文路径="+ ActionContext.getContext()); System.out.println("aaa="+ServletActionContext.getActionContext(ServletActionContext.getRequest())); filename=new String[myFile....

    Struts2中Servlet的配置

    2、使用struts2提供的ActionContext类直接获取Servlet API。 在同一个项目中,如果既用到servlet又用了struts框架,运行项目时可能无法正常使用servlet,解决办法如下: 该类是定义了一个过滤器,当既用到struts2...

    struts2流程与流程图

    一个请求在Struts 2框架中的处理大概分为以下几个步骤。...Struts 2的核心控制器是FilterDispatcher,有3个重要的方法:destroy()、doFilter()和Init(),可以在Struts 2的下载文件夹中找到源代码,如代码1所示。

    Struts2访问servlet分享

     ActionContext ctx = ActionContext.getContext();  ctx.getApplication().put(“app”, “应用范围”);//往ServletContext里放入app  ctx.getSession().put(“ses”, “session范围”);//往session里放入ses  ...

    struts2_OGNL表达式ActionContext及valuesStack

    struts2 OGNL,struts2 表达式语言,Struts2 中OGNL表达式的用法,Struts2 #,表达式语言的好处,Struts2 $,struts2 井号,星号,百分号

    Struts2整合SiteMesh技巧

    注意ActionContextCleanUp过滤器必须在FilterDispatcher之前配置,ActionContextCleanUp的主要功能是通知FilterDispatcher执行完毕不要清除ActionContext,以便sitemesh装饰器可以访问Struts值堆栈。 配置装饰器 ...

Global site tag (gtag.js) - Google Analytics