4. What is Struts2 Framework
A framework tries to automate the common tasks and
provides a platform for the users to build applications
quickly.
www.rajkrrsingh.blogspot.com
5. What is Struts2 Framework
Struts 2 is a very well-designed and flexible.
An integration of Struts 1 with OpenSymphony Web Works
Framework
www.rajkrrsingh.blogspot.com
6. What is Struts2 Framework
Struts 2 framework implements the Model-View-Controller (MVC)
design pattern.
–Model- use any data access technologies like JDBC, EJB, Hibernate
etc
–View- integrated with JSP, JSTL, JSF, Jakarta
Velocity, Templates, PDF, XSLT etc.
–Controller- based on many standard technologies like Java
Filters, Java Beans, ResourceBundles, XML etc.
www.rajkrrsingh.blogspot.com
10. The Core Components
Controller : Filter dispatcher, by which all the requests to the
applications gets filtered.
Interceptors : called after filters, apply common functionalities like
validation, conversion etc before Action methods.
Action : has execute methods, usually storing and/or retrieving
information from a database for the view,i.e the jsp files.
Result : Render the output as a view component i.e jsp file.
www.rajkrrsingh.blogspot.com
11. Request Cycle:
1.Container pass request to filter chain.
2.Chain includes the (optional) ActionContextCleanUp filter (useful
when integrating technologies such as SiteMesh Plugin)
3.Required FilterDispatcher is called and consults with ActionMapper
to determine if the request should invoke an action.
4.If Action should be invoked, the FilterDispatcher delegates control to
the ActionProxy.
5.The ActionProxy consults the framework Configuration Files
manager (initialized from the struts.xml file).
6.Next, the ActionProxy creates an ActionInvocation, which is
responsible for the command pattern implementation.
7.This includes invoking any Interceptors in advance of invoking the
Action itself.
www.rajkrrsingh.blogspot.com
12. Response Cycle:
1. When Action returns, the ActionInvocation=>looking up=>Action
result code mapped in struts.xml.
2.The result is then executed, which often involves a template written in
JSP to be rendered.
3.While rendering, the templates can use the Struts Tags provided by the
framework.
4.Interceptors are executed again in reverse order.
5.If the ActionContextCleanUp filter is present, the FilterDispatcher will not
clean up the ThreadLocal ActionContext. (One can use ThreadLocal to
keep certain objects/values available throught the thread execution.)
6.If the ActionContextCleanUp filter is not present, the FilterDispatcher will
cleanup all ThreadLocals.
www.rajkrrsingh.blogspot.com
13. Why Struts 2 - Features
Simplified Design
–Classes are based on interfaces
–Action classes are simple POJOs
Simplified Actions
–Any java class with execute() method can be used as an Action
class.
–Inversion of Control is introduced while developing the action
classes
•(actions to be neutral to the underlying framework .)
www.rajkrrsingh.blogspot.com
14. Why Struts 2 - Features
No more Action Forms
Annotations introduced
Stateful Checkboxes
Easy Spring integration
Easy plugin
AJAX support
Better Tag features
Both JSP and FreeMarker tags are fully supported.
www.rajkrrsingh.blogspot.com
21. Struts-default.xml
Shipped in struts2-core.x.x.jar
Most of your packages will extends Directly / Indirectly
Contains about everything you need.
Package from inheritance hierarchy.
The Key section are
package
result-Type
interceptors/stack
www.rajkrrsingh.blogspot.com
22. Interceptors
Responsible for most of the processing done by the framework.
Handle most of the fundamental preprocessing and post-processing
tasks.
Instead of invoking an action directly, this sits between the controller and
the action.
The invocation of an action is a layered process that always includes the
execution of a stack of interceptors prior to and after the actual execution
of the action itself.
www.rajkrrsingh.blogspot.com
23. Struts2 tags
Struts2 support following types of tags
A.UI Tags
i.Form Tags
ii.Non Form UI Tags
iii.Ajax Tags
B.Generic Tags
i.Control Tags
ii.Data Tags
www.rajkrrsingh.blogspot.com
24. Struts2 tags
A.UI Tags
render the HTML form and non-form componnets.
<textfield>
<password>
<hidden>
<textarea>
<radio>
<checkbox>
<checkboxlist>
<select>
<combobox>
<head>
<file>
www.rajkrrsingh.blogspot.com
25. OGNL
•Powerful expression language that is used to reference and
manipulate data on the ValueStack.
•Helps in data transfer and type conversion.
•Very similar to the JSP Expression Language.
•Based on a context and Struts builds an ActionContext map for use
with OGNL.
•The ActionContext map consists of the following:
•application - application scoped variables
•session - session scoped variables
•root / value stack - all your action variables are stored here
•request - request scoped variables
•parameters - request parameters
•atributes - the attributes stored in page, request, session and
application scope
www.rajkrrsingh.blogspot.com