actioncontext

ActionContext和ServletActionContext

痞子三分冷 提交于 2019-12-04 00:28:11
前面已经了解到ActionContext是Action执行时的上下文,里面存放着Action在执行时需要用到的对象,我们也称之为广义值栈。 Struts2在每次执行Action之前都会创建新的ActionContext,在同一个线程里ActionContext里面的属性是唯一的,这样Action就可以在多线程中使用。 1 :ActionContext 的线程安全性 那么Struts2是如何保证ActionContext的线程安全性呢? 看看ActionContext对象的代码,示例如下: public class ActionContext implements Serializable { static ThreadLocal actionContext = new ThreadLocal(); …… } ThreadLocal又称为“线程局部变量”,它为每一个使用该变量的线程都提供一个变量值的副本,使每一个线程都可以独立地改变自己的副本,而不会和其它线程的副本冲突。 存放在ActionContext里的数据都存放在这个ThreadLocal的属性中,而这个属性只会在对应的当前请求线程中可见,从而保证数据是线程安全的。 2 :访问的是Map 回顾前面在使用ActionContext来访问Session中数据的程序,你会发现,其实在程序里面访问的是一个Map

How to get an ActionContext from Struts 2 during acceptance tests?

情到浓时终转凉″ 提交于 2019-12-03 21:13:38
问题 I am writing acceptance tests (testing the behavior) using cucumber-jvm, on an application with Struts 2 and Tomcat as my Servlet Container. At some point in my code, I need to fetch the user from the Struts 2 HttpSession , created by an HttpServletRequest . Since I'm doing tests and not running Tomcat, I don't have an active session and I get a NullPointerException . Here's the code I need to call: public final static getActiveUser() { return (User) getSession().getAttribute("ACTIVE_USER");

Struts2源码阅读之ActionContext

与世无争的帅哥 提交于 2019-12-02 15:58:16
上一篇文章概述了Struts2的一些流程。这次说下ActionContext,直接进入正题。 static ThreadLocal actionContext = new ThreadLocal();//ActionContext public static ActionContext getContext() { return (ActionContext) actionContext.get(); } 从上面可以看到ActionContext 是被存放在当前线程中的,获取 ActionContext 也是从 ThreadLocal 中获取的。因此在执行拦截器、 action 和 result 的过程中,由于他们都是在一个线程中按照顺序执行的,所以可以在任意时候从 ThreadLocal 中获取 ActionContext 。 ActionContext是Action执行时的上下文,上下文可以看作是一个容器 Map<String, Object> context; public static void setContext(ActionContext context) { actionContext.set(context); } public static ActionContext getContext() { return (ActionContext)

Scopes of ActionMapper, ActionProxy, ActionInvocation, ActionContext objects in Struts2?

孤街浪徒 提交于 2019-12-02 08:06:56
Can any one please describe me when the objects of ActionMapper , ActionProxy , ActionInvocation , ActionContext are created in a Struts2 application. As I am new to Struts2 framework, I am very much confused about the scopes of these objects. The ActionMapper is created on startup, it has a singleton scope. The ActionContext is created by the Dispatcher in preparing an action to execute, it's ThreadLocal , and it doesn't have any scope. When action is executing the ActionInvocation and ActionProxy are created that also don't have a scope. You can see this on a big picture of Struts2

How many sessions can be managed by an Java Application in Struts 2?

孤人 提交于 2019-12-02 07:34:32
I am working on Transaction Management application, and I am using Struts2. I have used internally a session for setting and getting values like ActionContext.getContext().getSession().put("string", string); Is there any limit or any disadvantage of using a session like this in the application? Limit is the size of your computers physical memory.you dont store dynamic values in session because someone can modify them in the meanwhile , so store only those values in session which represent any user specific data or static values (i.e. which are not going to be changed while session exists).

Struts2 JUnit ActionContext objects

孤街浪徒 提交于 2019-12-01 13:27:53
Problem: Struts ActionContext is null during test Using Struts2 JUnit plugin I have the following test: public class MainActionIT extends StrutsJUnit4TestCase { @Test public void testAction() { Map<String, Object> application = new HashMap<String, Object>(); application.put("options","home"); ActionContext.getContext().put("application",application); ActionProxy proxy = getActionProxy("/home"); String result = proxy.execute(); } } The two related classes are as follows: public class MainAction extends BaseAction { @Action(value = "/home", results = {@Result(name = "success", location = "home

Struts2 ActionContext and ValueStack?

自古美人都是妖i 提交于 2019-12-01 08:31:47
My questions are: In Struts2, does every action object have its own corresponding ActionContext and ValueStack? In other words, for every new request a new action object is created. Does this mean every time a new action object is created, a new ActionContext and ValueStack also get created? Consider this scenario: Action1------1st req------->view.jsp------2nd req--------->action2. So when a request comes for action1 a new object of action1 and corresponding ActionContext and ValueStack will get created. From view.jsp (upon clicking hyperlink) a new request goes for action2. Does this mean

How to get an ActionContext from Struts 2 during acceptance tests?

谁说我不能喝 提交于 2019-11-30 23:15:15
I am writing acceptance tests (testing the behavior) using cucumber-jvm, on an application with Struts 2 and Tomcat as my Servlet Container. At some point in my code, I need to fetch the user from the Struts 2 HttpSession , created by an HttpServletRequest . Since I'm doing tests and not running Tomcat, I don't have an active session and I get a NullPointerException . Here's the code I need to call: public final static getActiveUser() { return (User) getSession().getAttribute("ACTIVE_USER"); } And the getSession method: public final static HttpSession getSession() { final HttpServletRequest

Strut 2.3.1.2 Unit test, how to remove Spring codependency vs NPE with getContext()

a 夏天 提交于 2019-11-29 18:21:19
I'm just upgrading to Struts 2.3.1.2, and having a few issues with JUnit tests. My old test code was like this.... public class HomeActionTest { @Test public void testUserNameErrorMessage() throws Exception { HomeAction action = new HomeAction(); setupMocks(action); action.execute(); } } The action class's execute method has the code String text = getText(GLOBAL_SELECT); This causes a NullPointerExeception though in LocalizedTextUtil since it calls... ActionContext.getContext() Now I could try and do this... ActionContext.setContext(new ActionContext(new HashMap())); But then I'll get a

Is it possible to configure unified format of date format for whole struts webapp?

对着背影说爱祢 提交于 2019-11-28 14:45:40
In any case id get exception Could not parse date . There is unified company standard of date format - 'dd/MM/yyyy' There are computers with different system locales. I am using jQueryUI for datepicker ( it is standard for widgets and already settled css styles to match application theme). At the beginning, i didn't found better solution then manually convert date string to date object using SimpleDateFormat object. Now i have converter class but still need to configure every Action that has java.util.Date property. I am using XML configuration and I did try to add into struts.xml : <constant