top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Migrating Struts1 application to Struts2

+1 vote
658 views

I am migrating an application from Struts 1 to Struts 2 and frequently I am facing scenarios where I need to use request.getSession to set/get attributes. As far as my knowledge goes, this is not considered to be a best practice in Struts 2. What is the best was way to handle this scenario?

posted Sep 3, 2013 by Sumit Pokharna

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
answer Sep 3, 2013 by Garima Jain
Thanks a lot.
I can get the values in userSession which will be like session.getAttribute.. but what about session.getAttribute?? Can I set a key value pair in userSession and it will automatically picked up ?
yes... you can set session as Key Value pairs and retrieved easily in Struts2. Struts2 OGNL expressions can be used in getting session value from the value stack. My Sturts2 knowledge is average. so you can refer some tutorials for more clarification
Similar Questions
+1 vote

We are in the beginning of the migration to struts2 and it seems like there will be some period when both frameworks will be active at the same time..the only problem now is accessing the session beans managed by struts2 in struts1 and vice-versa form beans from strut1 mapped in struts2 . Half of the jsp would use struts1 tags and other half struts2 tags. So there should be beans instantiated in both frameworks.

Probably struts2 bean can be injected to struts1 action with struts1 form still accessible as execute() argument, but what about other way? accessing struts1 form bean (not just data, but managed bean) in struts2 execute() ?

+1 vote

I have a requirement to use Struts 2.x framework for new modules in the existing web application which is currently running on Struts 1.x

I would like to have both configuration separately and I don't wish to migrate or touch any of existing source files.

Could you please provide me any sample application or user guide or any related information for my requirement? Appreciate your kind help on this.

+7 votes

I have an Interceptor that wants to put something in the session after the action has executed.

But if the session doesn't already exist I get an exception:

java.lang.IllegalStateException: Cannot create a session after the response has been committed

How can I determine if the session already exists from within an Interceptor?

 public String doIntercept(ActionInvocation invocation) throws Exception
 {
 String result = invocation.invoke();
 Map session = invocation.getInvocationContext().getSession();
 session.put(key, value); // throws exception if session doesn't exist
 return result;
 }
...