Docsity

Struts Basics Part 1-Java Programming-Lecture Slides, Slides of Java Programming

Partial preview of the text

Download Struts Basics Part 1-Java Programming-Lecture Slides and more Slides Java Programming in PDF only on Docsity!

Advanced Java Programming

Lecture 16 – STURTS BASICS

Agenda

 What is and Why Struts?  Struts architecture  Controller: Focus of this presentation  Model  View  Struts tag library (moved to StrutsTags presentation)  Internationalization  Validation and error handling  View selection  Issue with Struts

Jakarta Struts

 Struts is an open source Web application framework developed as Apache Jakarta project  http://jakarta.apache.org/struts/

What is Struts?

 Model-View-Controller (MVC) framework  Used for constructing web applications using Servlets and JSPs  Struts application is a genuine Web application that should be able to run on any Sevlet container including all J 2 EE compliant App servers  Pattern oriented  Singleton, composition view, delegate  Easy to use and learn  Includes JSP custom tag libraries (Sturts own)

Struts allows Web Application Developers

to ...

 Fashion their JSP/Servlet web applications using the MVC design pattern  Leverage ready-to-usable framework objects through xml configuration files  Leverage built-in design patterns in the framework  Leverage extra features such as input validation, internationalization

Why Struts?

Why Struts?

 Integrates well with Java EE (J 2 EE)  Good taglib support  Works with existing web apps  Easy to retain form state  Unified error handling programmatically and declaratively  Integration with Tiles framework  Clear delineation of responsibility makes long term maintenance easier (more modular)

Struts Architecture

(Quick Overview)

How Struts Works

Struts: MVC-based Architecture

 Central controller mediates application flow and

delegates to appropriate handler called Action

 Action Handlers can use model components

 Model encapsulates business logic or state

 Control forwarded back through the Controller to

the appropriate View

 The forwarding can be determined by consulting a set of mappings in configuration file, which provides a loose coupling between the View and Model

Struts: MVC-based Architecture

 Configuration file contains action mappings  URL to Action mappings  Controller uses these mappings to turn HTTP requests into application actions  Determines forwarding/navigation  Mapping must specify  A request path  Action to act upon the request

Controller

source: Chuck Cavaness docsity.com

Controller in Struts Framework

 Struts framework provides a built-in base servlet  org.apache.struts.action.ActionServlet  Servlet mapping has to be configured in web.xml  Struts related configuration is done through struts- config.xml  Action Mapping defines the mapping between request URI of incoming requests to specific Action class