actioncontext

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

纵然是瞬间 提交于 2019-12-20 07:16:25
问题 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? 回答1: 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

Set locale via code in Struts2

五迷三道 提交于 2019-12-18 07:25:09
问题 In my application, I have to display the content based on the locale user chosen in the configuration page. I am not using browser default locale. when using s:text , it always use the default resource file. In Struts1, I have used the below code to set default locale in my filter session.setAttribute("org.apache.struts.action.LOCALE",locale); How to set the user chosen locale dynamically in Struts2 ? 回答1: This worked for me : String language = userLocale.substring(0, 2); String country =

Will a new ActionContext and ValueStack be created for every new action object?

强颜欢笑 提交于 2019-12-13 00:57:39
问题 My questions are: 1) 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? 2) 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

What's the purpose of storing objects directly to the ValueStack/ActionContext?

╄→гoц情女王★ 提交于 2019-12-12 06:04:40
问题 Based from what I've researched, I've seen that tags such as <s:set> , <s:push> or by creating an <s:bean> are able to insert references directly to the ActionContext or ValueStack . This confuses me a lot because why can't you just have one dedicated place to store everything? Probably just put everything in the ActionContext since it's basically acts as a ServletContext . To make it even more confusing, if you wanted to access values in the ValueStack , you'll have to use Struts tags such

Is ActionContext in Struts 2 unique to the current request?

◇◆丶佛笑我妖孽 提交于 2019-12-11 18:03:19
问题 I'm using a custom interceptor which creates a new db connection, and sets this connection onto the current action before executing the action. After that, the interceptor closes the connection. I'm looking for a convenient way to share this db connection with other classes / static methods (such as Models) that are used by the action. E.g so I can call static method like User.get( id ) or User.getEmail( id ) without having to pass the db connection to each method separately. I could set the

ActionContext.getContext().getParameters() returns null during StrutsJUnit4TestCase

廉价感情. 提交于 2019-12-10 18:58:34
问题 I am running a JUnit test via maven where a struts action java method is being tested that makes the following call: // Gets this from the "org.apache.struts2.util.TokenHelper" class in the struts2-core jar String token = TokenHelper.getTokenName(); Here is the method in "TokenHelper.java": /** * Gets the token name from the Parameters in the ServletActionContext * * @return the token name found in the params, or null if it could not be found */ public static String getTokenName() { Map

Should I get the session through SessionAware or ActionContext?

假装没事ソ 提交于 2019-12-07 10:06:51
问题 After reading the differences between obtaining the session map via ActionContext.getContext().getSession() and having it injected through SessionAware I was wondering which is the preferred method, and why? The API recomends to use SessionAware , and I read on the web that using SessionAware makes the application easier to test--is testing the only issue? Can someone elaborate a little bit on this subject or point out to references explaining this? 回答1: I have already replied the same in

How do you get a Struts2 value from the .properties file programatically?

旧巷老猫 提交于 2019-12-06 13:35:57
Say I have a struts.properties file with a defined value uploads.directory . How can I access that value from an Actioncontext programatically? Roy Chan You can use getText("some.property.name") which return you the property value http://struts.apache.org/maven/struts2-core/apidocs/com/opensymphony/xwork2/ActionSupport.html Bhanwar Rathore Create ActionSupport Object and by using getText() method of ActionSupport class. ActionSupport actionSupport = new ActionSupport(); actionSupport.getText("foo.bar"); Waqar Create a resources folder under src . In the struts.xml file add a constant e.g.,

Mocking ActionContext.getContext().getSession() returns null

两盒软妹~` 提交于 2019-12-06 09:35:49
I am trying to write jUnit test case for following method. public class MyClass { public static Map<String, Object> getSession() { Map<String, Object> session = ActionContext.getContext().getSession(); return session; } } I followed this question and also this question and tried to mock ActionContext . But still session is null . public class TestClass { private HttpServletRequest request; private HttpSession session; @Before public void setUp() { // mock the session session = mock(HttpSession.class); // mock the request request = mock(HttpServletRequest); when(request.getSession()).thenReturn

Struts2 ActionContext and ValueStack?

浪子不回头ぞ 提交于 2019-12-04 01:43:02
问题 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