top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is Action Class in Strurts?

+5 votes
What is Action Class in Strurts?
posted Feb 9, 2014 by Neeraj Pandey

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

1 Answer

0 votes

Action Class in Struts framework is used to define the business logic it handle the client request prepare the response or tell where the response should be forward, basically its receive the data from the view layer and forward that data to specific business layer or process the data and again forward the processed data to view layer.

For example Action class can create a library object add books to that library object, it can store selected books by specific reader to session.

In Brief we can describe Action as:

  • Our Action class is extended by “org.apache.struts.action.Action class”.
  • We need to override execute() method of Action class.
  • Action servlet select Action class for incoming HTTP Request defined under the action mapping tag in struts config.xml file
  • Action class is used to invoke business or data access logic get data from bean and store processed data to bean and return result or errors depending upon the situation,
  • Action classes are multi-threaded so we need to carefully handle the action variable as they are not thread safe when working with multi-threaded environment.

How to Use Action Class In simple steps we will see how to use Action class.

  • First extend the org.apache.struts.action.Action class.
  • Override following method
   public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws IOException, ServletException

Here we develop our business logic and prepare the response to return the client.

  • Then we configure this action to struts config file of our application inside action mapping :
      <forward name="success" path="/ExamplePages/TestAction.jsp"/>
answer Feb 9, 2014 by Jai Prakash
Similar Questions
0 votes

In the context of an tag, for instance for a login action, we previously always coded forms as :


And in the struts.xml we have been using :


This has worked in the past and allowed us to not only use the action="login" to target the execute method of the action, but also to build links to, for instance, login_checkStatus.action to target other, specific methods within the action. I am not sure this Is a common/best practice, I had no prior struts2 experience before joining this company and this is how a lot of the existing functionality is coded. (If this is wrong/there is a better way, please let me know)

Now randomly, this fails to generate the proper action url in the html (it is missing the '.action', which results in a 404 once you post the form)

The only workaround we have found so far is to add the '.action' suffix to the
s:form's action attribute. Before it was always added for us by struts.

So now we are having success with


I can only assume that this has been affected by the changes related to S2-015 and the wildcard action matching.

0 votes

I have been using struts quite a long time, but in the last days I have faced a strange behaviour of s:action tag.

In my JSP I am using the tag action to load list to be used to mount my s:select. But in the redered HTML, the result of the action is showing, even when the executeResult is false.

There is something I missing?

JSP code:



As you can see, in the struts.xml, I have only json result, and I only need as json, but when I use the action tag, I just only need the populated list to be used in the select tag. It is working very well, but the problem is that the json result is showing in the HTML. And it is showing in the top, not in the action tag position, what is strange.

Also, I try to change the struts.devMode to false, but nothing changes.

The project is using struts with rest-plugin. But for this kind ok action, I avoid rest and use just json-plugin.

+1 vote

In struts2 , defined an interceptor, it triggered by Action, my question is

"inside the interceptor class, what is the function call that can tell caller's name, because that interceptor could be triggered by different Action, we need to log the caller's name, but how?"

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.