J2EE Struts Framework
SHISHIR KR SINGH
CUSAT
15th March 2019
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 1 / 17
Topics Covered
What is Framework
Model 1, Model 2
What is Struts
Why we need it
Advantages of Struts
Controller Elements
View Elements
Model Elements
Conclusion
References
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 2 / 17
What is Framework
A basic structure underlying a system,concept or text.
A software framework is a re-usable design for a software system(or
subsystem).
Advantages
Provide a procedure for development of application.
Provide low-level services that developers can use to speedup
development.
Reduces software development and maintenance costs.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 3 / 17
Model 1
In the Model 1,the JSP page is responsible for processing the incoming
request and replying back to client.
It does not have separate controller.
Designers and Developers must work on the same files.
It leads to a significant amount of Java code embedded within the
JSP page.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 4 / 17
Model 2
The Model2 approach combines the use of both Servlets and JSP,
using JSP to generate the presentation layer and servlets to perform
process-intensive tasks.
No proceesing/business logic within the JSP page.
The controller provides a single point of control for security and often
encapsulates incoming data into a form usable by the back-end model.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 5 / 17
What is Struts
An open source web application framework based on j2ee and java
which implements the MVC design pattern.
Why we use:
It is an open source.
It makes complex applications into simpler ones.
Provides components for building web applications that speedup
development and saves time for developers.
Built in exception handling.
Built in validation framework.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 6 / 17
Struts Framework Components
Controller components - Direct the action.
Model components - Access data and Systems.
View components - What the users see.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 7 / 17
ControlLer Compnonents
ActionServlet
I Receive the HttpServletRequest.
I Determine which action to invoke.
I Automatically populate a JavaBean from the request parameters.
I Handles other local issues.
I Dispatch request to RequestProcessor.
RequestProcessor
I Finds ActionMapping.
I Mapping Action to Formbean.
I Creating FormBean object.
I Calling Validator of Formbean.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 8 / 17
Action Class
I Acts as a bridge between user invoked URI and a business method.
I Returns information about which view should be rendered next.
Struts-Config.xml
I Configuration file contains action mapping.
I Tags in this file are:
F data sources
F Form beans
F Exceptions
F Actions
F Message resources
F Plug-ins
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 9 / 17
Configuration file example
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 10 / 17
The Model components
Java classes.
Middle tier components(EJB, Javabeans,...) - used to represent the
internal state of the system.
Databse access components.
Action Form.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 11 / 17
Action Form
Extends the ActionForm class.
Just like a java bean, stores data temporarily, validates input view.
If defined in the action-mapping configuration file, controller servlet
will performt he following:
I check for instance of bean of appropriate class.
I if no bean exists, one is created automatically.
I the updated ActionForm bean will be passed to the Action class
execute() method when it is called making these values immediately
available.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 12 / 17
Action Form example
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 13 / 17
The View components
JavaServer Pages(JSP)
HTML
Javascript and Stylesheets
Multimedia files
JavaBeans (part of model used by view component)
JSP custom tags
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 14 / 17
Struts JSP Tag libraries
HTML
I used to create input forms.
I Ex - checkbox, image, submit, text etc.
Bean
I used for accessing JavaBeans and their properties.
I Ex - define, message, write etc.
Logic
I managing conditional generation of output text.
I Ex - empty, lessThan, greaterThan etc.
Tiles
I Each part of webpage can be reused as often as needed throughout the
application.
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 15 / 17
Refernces
https://www.slideshare.net/JayaPrakash.m/strutsppt1/4
https://www.tutorialspoint.com/struts2 /ugweb.cs.ualberta.ca/ c410ta/F 07/s
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 16 / 17
The End
SHISHIR KR SINGH (CUSAT) J2EE Struts Framework 15th March 2019 17 / 17