Search This Blog
Friday, September 7, 2012
What is Struts Action Class in Java J2EE - How to use
is Action class in Struts
Struts in java is a framework, used to make web application its is based
on Model View Controller or MVC design Pattern where Model represent the
internal state and action used to change the state view represent presentation
component and controller is responsible for receiving the request from client
and decide which business logic should be called. Basically Struts have
different classes to represent this Model, View and Controller we call them as Action, Action Form,
and Action Servlet. So
Model – Action
View - Action
– Action Servlet classes
In this article we are focusing on the Model layer of struts framework.
Action class is used to provide an interface to application model layer. What is Action class and how to use Action class is a also a popular Struts interview Question asked in various J2EE interviews.
is Action Class in Struts ?
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.
Brief we can describe Action as:
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
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
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.
Use Action Class
In simple steps we will see how to use Action class.
1.First extend the org.apache.struts.action.Action
2.Override following method
public ActionForward execute(ActionMapping mapping,