Nik
Nik

Reputation: 201

Strut2: Is the Action not being created per request here?

Using Struts 2.1.6 with Tiles.

I am noticing some strange behavior in my Struts 2 actions. I have a breakpoint set in one of the actions (say view()). When I start the application server for the first time, click a link in my web app that executes this action, the debugger stops at the break point and I can troubleshoot the problem, the exception occurs and the message is displayed on the UI.

However, when the I click on the same link again the debugger does not hit the breakpoint and the UI displays the same error message. I click other links and other debug points work completely fine. When I click again on the same URL, the same message is displayed. I have to restart the server and repeat the process again.

Is something being cached somewhere? Do you think a new instance of struts action is not being created? How do I troubleshoot this? I have not posted any code yet because I am not sure what specific information you might need...

I am storing some object in session for pagination purpose, could that be the issue?

Upvotes: 1

Views: 1163

Answers (1)

Umesh Awasthi
Umesh Awasthi

Reputation: 23587

Well what i read from your description seems like problem is somewhere in your code.With each request struts2 create a new instance of your action class as well request and response and place them in value stack, so no matter what was the result of last execution, a new request always end up creating a new instance.

Creating new instance is as per the Framework architecture as Action also work as data transfer object (model).

I suggest you to check your configuration and see where exactly is problem.

As a side note are you using Strts2-spring plugin, using the plugin you need to set scope=prototype else spring by-default will create singleton action instance and same Action instance will be used again and again

Upvotes: 1

Related Questions