(一)通过ActionContext来获取request、session和application对象的LoginAction1 [java] ActionContext context = ActionContext.getContext...本站的访问量是:${applicationScope.counter} (二)直接使用ActionContex类的put()方法 ActionContext.getContext
Struts2会根据每个执行HTTP请求的线程来创建对应的ActionContext,即一个线程有一个唯一的ActionContext。...在自定义的拦截器中,先获得ActionContext,再通过ActionContext来获得。 在Action中,先获得ActionContext,再通过ActionContext来获得。...在自定义的拦截器中,先获得 ActionContext,再通过ActionContext来获得。 在Action中,先获得ActionContext,再通过ActionContext来获得。...ActionContext actionContext = ActionContext.getContext(); // 获得HttpServletRequest HttpServletRequest...另外,ActionContext还直接提供了ActionContext.getParameters()方法来获得这个Map。
而又提供了获取Servlet API的其它通道,就是ActionContext(别跟我说还有个ServletActionContext,其实ServletActionContext只是ActionContext...源码为证:public class ServletActionContext extends ActionContext implements StrutsStatics 其次,他也知道,ActionContext...那我们一起来看看吧: 首先是ActionContext类的源码:public class ActionContext implements Serializable{ static ThreadLocal...setContext(ActionContext context) { actionContext.set(context); } public static ActionContext getContext...() { return (ActionContext)actionContext.get(); } public void setContextMap(Map contextMap) { getContext
ActionContext:action的上下文对象。...获取application : // 获取ActionContext对象 是action的上下文对象 ActionContext actionContext = ActionContext.getContext...这个时候我们需要看下ActionContext的源码。...map嵌套map, session等对象是放在actionContext的value中.那么我们可以通过debug来获取ActionContext对象吧 通过我们也要根据actionContext的session...结构 差不多分析出来 request在actionContext的存放 应该是类似。
Struts2.0 提供了一个名字为ActionContext的类,在Action中可以通过该类获得Servlet API。 ...ActionContext是一个Action的上下文对象,Action运行期间所用到的数据都保存在ActionContext中(如Session,客户端提交的参数等信息)。 ...在Action中可以通过下面的代码来创建和使用ActionContext类,关于该类的方法介绍如下所示: ActionContext ac=ActionContext.getContext();...以下是ActionContext类的常用方法 1.Object get(Object key) :通过参数key来查找当前ActionContext中的值 2.Map getApplication...() :返回一个Application级的Map对象 3.Static ActionContext getContext() :获得当前线程的ActionContext对象 4.Map getParameters
完成数据迁移是由ActionContext来完成的。...2.ActionContext是Action处理类执行的上下文对象 ActionContext是一个Map结构的对象,属于一个容器。ActionContext是线程安全的。...并且ActionContext在struts2执行过程中负责数据的存储。 ?...ActionContext机制是将ServletAPI中的数据进行了解耦,在Action执行过程中,struts2都从ActionContext中获取数据。那么实现线程安全,同时也降低了执行效率。...ActionContext对象中的重要的对象 ? 另外,ThreadLocal的不错参考网址: https://www.cnblogs.com/dolphin0520/p/3920407.html
获取 ActionContext 对象 // ActionContext 是 Action 的上下文对象....可以从中获取到当前 Action 需要的一切信息 ActionContext actionContext = ActionContext.getContext(); /...parameters-name=:qbz 总结: 获取 ActionContext 对象: ActionContext actionContext = ActionContext.getContext(...对应的 Map: Map sessionMap = actionContext.getSession(); ActionContext 中手动传入 request 字符串来获取...Map Map parameters = actionContext.getParameters();
ActionContext类 常用方法 l getContext():返回ActionContext实例对象; l get(key):相当于HttpServletRequest的getAttribute...访问或添加request/session/application属性 public String execute(){ ActionContext actionContext=ActionContext.getContext...(); //往ServletContext中放入app actionContext.getApplication().put("app", "应用范围");...//往session中放入ses actionContext.getSession().put("ses", "session范围"); //往request中放入req...actionContext.put("req", "request范围"); return"success"; } 版权声明:本文内容由互联网用户自发贡献
3.1、ActionContext 充当OGNL的context。...如果我们使用actionContext.put(); 那么会将该键值对直接放入到ActionContext下。 注意:除了request外,其他都可以直接通过getXxx()获得。...从这里actionContext中是不能直接获取到的,request进行了怎样的增强呢?...3.3、ActionContext和valueStack的关系(重要) 也就是说,通过valueStack可以获取到actionContext,通过ActionContext也可以获取到valueStack...获取actionContext的方式 ActionContext.getContext(); //常用 valueStack.getContext(); 四、struts2中使用OGNL
1、创建session: ActionContext actionContext = ActionContext.getContext(); Map mapSession...= actionContext.getSession(); mapSession.put("branch", branch); mapSession.put("permission", per); 2...out.print("alert('您还没有登录,请登录') "); out.flush(); out.close(); } 3、java后台读取session的值 ActionContext...actionContext = ActionContext.getContext(); Map session = actionContext.getSession(); String inputUserid
actionContext=ActionContext.getContext(); Map session=actionContext.getSession();...actionContext=ActionContext.getContext(); Map session=actionContext.getSession(); Userlistener...actionContext=ActionContext.getContext(); Map session=actionContext.getSession();...*/ public int returnNum(){ ActionContext actionContext=ActionContext.getContext();...actionContext=ActionContext.getContext(); Map session=actionContext.getSession(); ArrayList
ActionFilterAttribute { public override void OnActionExecuting(Controllers.HttpActionContext actionContext...) { LogHelper.Warn(actionContext.ActionDescriptor.ActionName + "进入执行:", Utils.SerializeObject...(actionContext.ActionArguments)); base.OnActionExecuting(actionContext); }...); LogHelper.Error(actonName + "异常参数:", Utils.SerializeObject(actionExecutedContext.ActionContext.ActionArguments...{ LogHelper.Warn(actonName + "成功退出执行:", Utils.SerializeObject(actionExecutedContext.ActionContext.ActionArguments
解耦合方式 ---- 解耦合方式---ActionContext : 解耦合方式获取的都是map对象 1 //登录 2 public String login(){ 3...user.getName())&&"1111".equals(user.getPwd())){ 4 //登录成功 数据存入Session中 5 //通过ActionContext...可以获得Session 6 Map session = ActionContext.getContext().getSession(); 7...().get("request"); 12 Map application = ActionContext.getContext().getApplication...可以不在Servlet容器环境中使用 2.耦合方式获取ServletAPI ---- 下面讲的是耦合方式获取的Servlet对象 2.1 通过ActionContext获取 //登录 public
我们需要在Action中取得request请求参数"username"的值: ActionContext context = ActionContext.getContext(); Map params...一般情况, 我们的ActionContext都是通过: ActionContext context = (ActionContext) actionContext.get();来获取的.我们再来看看这里的...通过ActionContext取得HttpSession: Map session = ActionContext.getContext().getSession(); 2....ServletActionContext和ActionContext联系 ServletActionContext和ActionContext有着一些重复的功能,在我们的Action中,该如何去抉择呢?...注意:在使用ActionContext时有一点要注意: 不要在Action的构造函数里使用ActionContext.getContext(),因为这个时候ActionContext里的一些值也许没有设置
OnActionExecuted(HttpActionExecutedContext actionExecutedContext) 和OnActionExecuting(HttpActionContext actionContext..."_thisWebApiOnActionMonitorLog_"; public override void OnActionExecuting(HttpActionContext actionContext...) { base.OnActionExecuting(actionContext); WebApiMonitorLog MonLog =...; MonLog.HttpRequestHeaders = actionContext.Request.Headers.ToString(); MonLog.HttpMethod...= actionContext.Request.Method.Method; actionContext.Request.Properties[Key]
rollback(BusinessActionContext actionContext) { return accountService.rollbackDeduct(actionContext...(BusinessActionContext actionContext) { return orderService.rollbackOrder(actionContext); ... = (String) actionContext.getActionContext("productId"); Integer count = (Integer) actionContext.getActionContext... rollback(BusinessActionContext actionContext) { return storageService.rollbackDeduct(actionContext... = new BusinessActionContext(); actionContext.setXid(xid); storageServiceApi.deduct(actionContext
通过 Aware 接口获取 WEB 资源 在上一节中介绍了用ActionContext来获取WEB资源。...获取 ActionContext 对象 // ActionContext 是 Action 的上下文对象....可以从中获取到当前 Action 需要的一切信息 ActionContext actionContext = ActionContext.getContext(); /...获取 application 对应的 Map, 并向其中添加一个属性 // 通过调用 ActionContext 对象的 getApplication() 方法来获取 application...对象的 Map 对象 Map applicationMap = actionContext.getApplication(); // 设置属性
当请求过来的时候,执行 StrutsPrepareAndExecuteFilter过滤器当中的doFilter方法 在这个方法当中创建ActionContext 在创建ActionContext过程中,...创建ValueStack对象 将valueStack对象传递给ActionContext对象。...通过ActionContext获取值栈对象 ActionContext对象之所以能够访问servlet的API(域对象的数据)就是因为内部有值栈的引用,与action相关的存在根区请求完毕后清空,而其他域的数据存在非根区...值栈存数据 通过ActionContext类的静态方法getContext得到ActionContext对象,ActionContext对象调用getValueStack获取到值栈 ? ?...获取值栈 ValueStack valueStack = ActionContext.getContext().getValueStack(); 根区 // getRoot()可以省略 Student
= actionContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, actionContext.ModelState);...if (actionContext.Request.Method !...== false) { actionContext.Response = actionContext.Request.CreateErrorResponse...if (actionContext.Request.Method !...== false) { actionContext.Response = actionContext.Request.CreateErrorResponse
string Key = "__action_duration__"; public override void OnActionExecuting(HttpActionContext actionContext...) { if (SkipLogging(actionContext)) { ...stopWatch.Elapsed)); } } private static bool SkipLogging(HttpActionContext actionContext...) { return actionContext.ActionDescriptor.GetCustomAttributes().Any() || actionContext.ControllerContext.ControllerDescriptor.GetCustomAttributes
领取专属 10元无门槛券
手把手带您无忧上云