GeekMantra

Struts Framework

What a framework means?
• an extensible/generic/flexible architecture following set of standards and patterns
• Focuses on a specific domain (web / j2ee applications etc)
• Provides extension points
• Can be customized and used on projects
What is Struts Framework?
• Provide APIs those are used to create web applications
• Uses Java Beans, Java Servlets, and Java Server pages (JSP)
• Based on the MVC design pattern
• Rich set of tag libraries provided for presentation tier
• Extensible

Struts Framework

Struts API Zoo

Sturts API

• Most of the times we will extend ActionForm for making input page form beans and Action class for
putting the business logic like we did in servlet.
• We can customize controller parts also.
• Most of the API and tags works in internationalized fashion, so they will take data to display as a key
and we will define these key-values into properties file. So by default our application will be
multilingual.
• We can define our validation rules on user inputs into xml, means highly configurable and reusable
validation code.
• We can break our look and feel into tiles and each tile can be configured through xml, means making the
presentation configurable.
• We define the flow inside the struts-config.xml that makes our application flow highly configurable.
So waiting for what this is the right time to write HelloWorld…..

HelloWorld Setup

hello world

hello world

hello world

For accessing the application type following URL in your browser
http://localhost:8080/hello/welcome.do

1. Since the request ends at .do so the ActionServlet will get called. This servlet works as Front
Controller.

2. ActionServlet will take out /welcome from /welcome.do and look for mapping
3. it will found direct forward rule and will forward the request to /hello.jsp
4. when you submit the hello.jsp page in action it calls /hello.do
5. again step 1 and 2 will be repeated
6. Now this time it founds an action class and form associated with this action.
7. instantiate the form bean object, called the setter method for properties name matched and then called
the validate method which returns ActionErrors object
8. it check this object if empty then execution goes to HelloAction execute() method else it forward the
request to input="/hello.jsp"
9. in execute we cast the form, fetch the value and then added into request
request.setAttribute("message", "Your Message " + msg + " received!!!");
execute() returns ActionForward that hold the logical name of the page to be forwarded.
<forward name="success" path="/success.jsp"></forward>
And finally we see the success.jsp as a final output.

hello world