Struts 2 framework basic component

In nutshell struts is based on mvc design pattern. And we will talk about Struts 2 framework with its basic component to keep in mind.

Basic component are Model, View and Controller so here with struts we call them as action, result and FilterDispatcher respectivly.

When any request is made by client’s browser it is sent to FilterDispatcher(Controller). And Here FilterDispatcher plays its role and deiced which Action to process this request. Now just for instance consider FilterDispatcher has processed and it has forwarded the request to a Valid Action. So, Here the game begins and once the action is executed, a return(response) from a action that is called as result. This generated result then sent back to client’s browser and this way the process completes. It is pretty simple 😉

Now here is some equation:
Model = Model contains the data and the business logic. In Struts 2 the model is implemented by the Action component.
Controller = FilterDispatcher
View = Struts 2 the view is commonly implemented using JSP, Velocity Template, Freemaker or some other presentation-layer technology.

FilterDispatcher process the request and do the following:
Struts 2, The framework creates an instance of this action and associate it with the newly created instance of the ActionInvocation.

  • Invocation of action have to pass through a series of interceptors as defined(Optional) in the application’s XML file
  • Each time the invoke() method is called, ActionInvocation consults its state and executes whichever interceptor comes next.
  • ActionInvocation hands control over to the interceptor in the stack by calling the interceptors intercept() method.
  • The intercept() method of the interceptor inturn calls the invoke() method of the ActionInvocation till all the interceptors are invoked, in the end the action itself will be called and the corresponding result will be returned back to the user.

Some interceptor do work before the action is executed and some do work after the action is executed. It’s not necessary that it should do something each time it is invoked.

  • These interceptors are invoke both before and after the action.
  • First all the interceptors are executed in the order they are defined in the stack.

Then the action is invoked and the result is generated.

Again all the interceptors present in the stack are invoked in the reverse order.

The other important features of Struts 2 are OGNL and ValueStack.

Object-Graph Navigation Language (OGNL) is a powerful expression language that is used to reference and manipulate data on the ValueStack.

OGNL help in data transfer and type conversion


About Sanju
I am Software Programmer. I am working in JAVA/J2EE Technologies.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: