SlideShare a Scribd company logo
Building Web Applications With The Struts Framework Session WE06 – 11/20/2002 – 10:00-11:00 Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.
Session Outline Web Applications Backgrounder The Model-View-Controller Architecture The Struts Framework Building A Web Application With Struts Resources
Web Applications Backgrounder
Web Applications Backgrounder Web applications run over the  HTTP  protocol: Request/response oriented Stateless Web applications use varied presentation (markup) languages, and talk to varied client hardware devices: “ Standard HTML” -- not! Varying dynamic and JavaScript capabilities Wireless devices vary in capabilities, language dialect, and input device support
Simple Solutions ... for Simple Problems For relatively simple applications,  a simple architecture works fine For each page in the user interface ... Create a servlet, JSP page, or something similar The page includes: Logic to create the user interface Logic to retrieve required information from the database Logic to perform the appropriate business transaction Logic to update the corresponding database information And it's all mixed together in one source file This works fine for a Guest Book app, but what about something bigger?
What About Large Scale Applications? Disparate skill sets required: Presentation Layer -- User interface design, visual appearance, interaction model Application Layer  – Functional business logic to perform required transactions Persistence Layer  – Databases, directory servers, messaging, Enterprise JavaBeans TM  (EJBs) Application Deployment  – Networks, firewalls, public key infrastructures, load balancing, failover We need a fundamental organizing principle: The  Model-View-Controller  (MVC) architecture
The Model-View-Controller (MVC) Architecture
The Model-View-Controller Architecture Divides the overall functionality of an application into three layers: Model Layer  – Contains the functional business logic of the application, as well as a representation of the persistently stored data backing the application View Layer  – Contains the user interface, including mechanisms to accept user input and render results Controller Layer  – Contains the logic that manages the flow of individual requests, dispatching to the appropriate business logic component
The Model Layer Functional business logic: Should be modelled as JavaBeans or Session EJBs Should be reusable in non-web environments API exposes public methods for each logical unit of work (while hiding the details) Persistent data storage: Should manage permanent storage of application data Typically shared across many applications API should expose data retrieval and storage operations (while hiding the mechanisms)
The View Layer Creation of the user interface: Typically in HTML or an XML-based dialect Normally a combination of static and dynamic content Actual content varies depending on: Device or browser type User preferences / personalization Internationalization and localization requirements Accessibility requirements
The Controller Layer Incoming requests flow through a common path: Received by common component Standardized request pre-processing Dispatch to request-specific model component (business logic) Forward to business-logic-specified view component Standardized request post-processing Often called “Model 2 Design” in the JSP/Servlet community In modern design pattern terminology, Struts implements the  front controller  pattern.
The Struts Framework – An Implementation of the MVC Architecture
The Struts Framework – Architecture
The Struts Framework – Model Layer Struts does not restrict implementation techniques for model layer JDBC-accessed databases Enterprise JavaBeans O-R mapping tools Optional JDBC connection pool available Common design pattern: Action  acquires information from persistence tier Exposes information as request/session attributes View layer pulls data from attributes for display
The Struts Framework – View Layer Form Bean  maintains state of form input fields across requests: ActionForm  – Standard JavaBean design pattern DynaActionForm  – Property names and types defined in Struts configuration file In addition to properties, form beans define two standard methods: reset()  -- Reset form properties to initial state validate()  -- Perform field-level validations Form bean properties are typically Strings Allows redisplay of invalid input
The Struts Framework – View Layer Internationalization Support  enables locale-specific applications Locale  – Standard Java class representing a choice of language and/or country MessageFormat  – Standard Java class representing an individual message with replaceable parameters: “ {0} is not a valid credit rating” MessageResources  – Struts abstraction around sets of messages for supported locales ActionErrors / ActionMessages  – Struts collections of localized messages
The Struts Framework – View Layer JSP Custom Tag Libraries  – If you are using JSP pages for your presentation struts-bean.tld  – Fundamental bean manipulation and internationalization struts-html.tld  – “Smart” HTML elements struts-logic.tld  – Basic conditionals and iteration struts-template.tld  – Basic layout management
The Struts Framework – View Layer Standard tag libraries added in Struts 1.1: struts-nested.tld  -- “Nested” variants  of standard tags that resolve relative references against beans struts-tiles.tld  – Full features layout management library Contributed libraries added in Struts 1.1: struts-xxx-el.tld  – Versions of standard Struts tag libraries that support the  expression language  syntax of JSP Standard Tag Library
The Struts Framework – View Layer Validation Framework No-code-required field level validations Configured in an XML document included in the web application Optionally generates client side JavaScript to enforce validation rules Extensible architecture
The Struts Framework – Controller Layer ActionServlet  – Standard implementation of controller At application startup, reads configuration file and initializes resources [Struts 1.1]  PlugIn  – General start/stop hook On each request, implements the standard Struts  request processing lifecycle  (in Struts 1.1, implemented in  RequestProcessor ) Specialization / customization via subclassing [Struts 1.1] Sub-application  modules  support
The Struts Framework – Controller Layer Action  – Standard base class for  business logic components and adapters: Mapped to logical names by request processor Single instance per application (must be thread safe) Instantiated as needed, like servlets Implements the “Command Pattern” execute()  -- Invoked for each request Can (but typically does not) create response content directly Typically returns  ActionForward  to select resource to prepare response
The Struts Framework – Controller Layer Standard Request Processing Lifecycle 1: processLocale()  -- Record user's locale preference (if not already present) processPreprocess()  -- general purpose pre-processing hook processMapping()  -- select Action to be utilized processRoles()  -- perform security role-based restrictions on action execution processActionForm()  -- Create or acquire an appropriate  ActionForm  instance
The Struts Framework – Controller Layer Standard Request Processing Lifecycle 2: processPopulate()  -- Copy the request parameters into the form bean properties processValidate() --  Call form bean's  validate()  method processActionCreate()  -- Create or acquire an appropriate  Action  instance processActionPerform()  -- Call action's  execute()  method processActionForward()  -- Process returned  ActionForward  instance (if any)
The Struts Framework – Controller Layer XML Configuration Document (/WEB-INF/struts-config.xml) Standard place to configure all aspects of the application's behavior DTD included for optional (but recommended) validation Logical-to-physical mappings for Actions, ActionForms, and ActionForwards General configuration settings [Struts 1.1] Configuration Document per  module  if more than one
The Struts Framework – Commons Libraries Non-Struts Specific Logic Factored Out: commons-beanutils  – Generic bean property manipulation commons-collections  – Extensions to standard Java2 collections classes commons-dbcp  – Optional JDBC connection pool commons-digester  – XML parsing for configuration files commons-fileupload  – Support library for HTML file uploads
The Struts Framework – Commons Libraries Non-Struts Specific Logic Factored Out: commons-logging  – Application logging wrapper commons-pool  – Object pooling library commons-resources  – Message resources support library Commons-validator  – Field validation framework
Building Web Applications With Struts
Building Web Applications With Struts Now that we understand the architecture of Struts, let's look at parts of an example app that is built with it Struts includes a canonical example that is useful in determining whether you have installed things correctly struts-example.war Application models (part of) an email portal site that lets you maintain multiple subscriptions
Sample Application – Model Layer (Persistence Tier) Modelled via a  Data Access Object  (DAO) org.apache.struts.webapp.example.UserDatabase public interface UserDatabase { public User createUser(String username); public void close() throws Exception; public User findUser(String username); public User[] findUsers(); public void open() throws Exception; public void removeUser(User user); public void save() throws Exception; }
Sample Application – Model Layer (Persistence Tier) Default implementation based on loading an XML document into memory: o.a.s.e.memory.MemoryUserDatabase JDBC-based (or LDAP-based) implementation is easy to imagine, and would be transparent to the business logic Implementation selection implemented via a  PlugIn  ... see configuration file example later
Sample Application – Model Layer (Business Logic) Two common Struts design patterns illustrated View --> View --> Action Welcome Page has link to logon page: <html:link page=”/logon.jsp”>...</html:link> Logon page instantiates  LogonForm  bean Form submit goes to  “/logon”  action View --> Action --> View --> Action Setup action  “/editRegistration?action=Edit”  pulls data from “database” and populates form bean Registration page “ /registration.jsp”  displays current data Form submit goes to  “/saveRegistration”  action
Sample Application – View Layer (logon.jsp) <%@ page contentType=”text/html;charset=”UTF-8” %> <%@ taglib uri=”/WEB-INF/struts-bean.tld” prefix=” bean ” %> <%@ taglib uri=”/WEB-INF/struts-html.tld” prefix=” html ” %> < html:html  locale=”true”> <head> <title> < bean:message  key=”logon.title”/> </title> < html:base /> </head>
Sample Application – View Layer (logon.jsp) <body bgcolor=”white”> < html:errors /> < html:form  action=”/logon” focus=”username” onsubmit=”return validateLogonForm(this);”> <table border=”0” width=”100%”> <tr> <th align=”right”>   < bean:message  key=”prompt.username”/> </th> <td align=”left”> < html:text  property=”username” size=”16”/> </td> </tr>
Sample Application – View Layer (logon.jsp) <tr> <th align=”right”>   < bean:message  key=”prompt.password”/> </th> <td align=”left”> < html:password  property=”password” size=”16”/> </td> </tr> </table></ html:form > < html:javascript  formName=”logonForm” dynamicJavascript=”true” staticJavascript=”false”/> <script language=”Javascript” .../> </body></ html:html >
Sample Application – Controller Layer No application logic required – Struts does everything for you :-) Controller functionality is configured via XML-based files: struts-config.xml  – Struts controller configuration validation.xml  – Validator framework configuration web.xml  – Web application configuration
Sample Application – Struts Configuration (struts-config.xml) <struts-config> <form-beans> ... <form-bean name=”logonForm” type=” org.apache.struts.action.DynaActionForm ”> <form-property name=”username” type=” java.lang.String ”/> <form-property name=”password” type=” java.lang.String ”/> </form-bean> <form-bean name=”registrationForm” type=” org.apache.webapp.example.RegistrationForm ”/> ... </form-beans>
Sample Application – Struts Configuration (struts-config.xml) <global-forwards> <forward name=”logoff” path=”/logoff.do”/> <forward name=”logon”  path=”/logon.do”/> <forward name=”registration” path=”/registration.jsp”/> <forward name=”success”  path=”/mainMenu.jsp”/> </global-forwards>
Sample Application – Struts Configuration (struts-config.xml) <action-mappings> <action path=” /editRegistration ” type=” org.apache.struts.webapp.example.EditRegistrationAction ” name=”registrationForm” scope=”request” validate=”false”> <forward name=”success” path=”/registration.jsp”/> </action> <action path=” /saveRegistration ” type=” org.apache.struts.webapp.example.SaveRegistrationAction ” name=”registrationForm” scope=”request” validate=”true” input=”registration”/>
Sample Application – Struts Configuration (struts-config.xml) <action path=” /logon ” type=” org.apache.struts.webapp.example.LogonAction ” input=”request” name=”logonForm” scope=”request”/> ... </action-mappings> <controller> <set-property property=”inputForward” value=”true”/> </controller> <message-resources parameter=” org.apache.struts.example.ApplicationResources ”/>
Sample Application – Struts Configuration (struts-config.xml) <plug-in  className=” org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn ”> <set-property property=”pathname” value=”/WEB-INF/database.xml”/> </plug-in> <plug-in className=” org.apache.struts.validator.ValidatorPlugIn ”> <set-property property=”pathnames” value=”/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml”/> </plug-in> </struts-config>
Sample Application – Struts Configuration (validation.xml) <form-validation> <formset> <form name=” logonForm ”> <field property=”username” depends=”minlength,...”> <arg0 key=”prompt.username”/> <arg1 key=”${var:minlength}” name=”minlength” resource=”false”/> <var><var-name>minlength</var-name> <var-value>3</var-value></var> ... </field> ... </form> ... </formset> </form-validation>
Sample Application – Webapp Configuration (web.xml) <web-app> <servlet> <servlet-name>Controller</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/struts-config.xml </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet>
Sample Application – Webapp Configuration (web.xml) <servlet-mapping> <servlet-name>Controller</servlet-name> <url-pattern>  *.do  </url-pattern> </servlet-mapping> ... </web-app>
Current Events
Struts 1.1 Release When?  “Real Soon Now” What new features? Apache Commons Libraries DynaActionForm Declarative Exception Handling Nested Tag Library PlugIn API Sub-Application Module Support (Contributed) STRUTS-EL Tag Libraries
Struts and JSTL JSP Standard Tag Library (JSTL) 1.0: Expression language (“${customer.address[“mailing”].city”) General purpose actions (out, set, remove, catch) Conditional actions (if, choose, when, otherwise) Iterator actions (forEach, forTokens) URL actions (import, url, redirect, param) Internationalization actions (message, setLocale, bundle, setBundle, message, param, requestEncoding) Formatting actions (timeZone, setTimeZone, formatNumber, parseNumber, formatDate, parseDate)
Struts and JSTL JSP Standard Tag Library (JSTL) 1.0, continued: SQL actions (not relevant in an MVC framework environment) XML core actions (parse, out, set) XML flow control actions (if, choose, when, otherwise, forEach) XML transform actions (transform, param) The  struts-xxx-el  libraries are a bridge for Struts developers who want to leverage JSTL tags, and expression language syntax, now
Struts and JSF JavaServer Faces (currently under development in JSR-127) Goals: Standard GUI component framework for web applications RenderKits for different rendering environments (browser vs. wireless device, different locales, etc.) Struts  will  provide an integration library: Requires changes to view layer and struts-config.xml file  only ! Plugs in to  RequestProcessor  APIs
Resources
This Presentation Online StarOffice 6.0: http://www.apache.org/~craigmcc/apachecon-2002-struts.sxi Powerpoint: http://www.apache.org/~craigmcc/apachecon-2002-struts.ppt
Internet Technologies Hypertext Markup Language (HTML) 4.01: http://www.w3.org/TR/html4/ Hypertext Transfer Protocol (HTTP) 1.1: http://www.ietf.org/rfc/rfc2616.txt Uniform Resource Identifiers (URI): http://www.ietf.org/rfc/rfc2396.txt
Model Layer – Standard Java APIs JavaBeans: http://java.sun.com/products/javabeans/ Java Database Connectivity (JDBC): http://java.sun.com/products/jdbc/ Java Data Objects: http://java.sun.com/products/jdo/ http://jcp.org/jsr/detail/12.jsp Java Naming and Directory Interface: http://java.sun.com/products/jndi/ Enterprise JavaBeans (EJB): http://java.sun.com/products/ejb/
Model Layer – Persistence Frameworks Castor: http://castor.exolab.org/ Java Data Objects: http://java.sun.com/products/jdo/ Object/Relational Bridge: http://jakarta.apache.org/ojb/ Torque: http://jakarta.apache.org/turbine/torque/
View Layer – Standard Java APIs Servlets: http://java.sun.com/products/servlet/ JavaServer Pages (JSP): http://java.sun.com/products/jsp/ JSP Standard Tag Library (JSTL): http://java.sun.com/products/jsp/jstl/ JavaServer Faces: http://java.sun.com/j2ee/javaserverfaces/ http://jcp.org/jsr/detail/127.jsp
Struts Resources The Struts and Commons Web Sites: http://jakarta.apache.org/struts/ http://jakarta.apache.org/commons/ Recent Books About Struts: Cavaness, Chuck;  Programming Jakarta Struts ; O'Reilly Goodwill, James;  Mastering Jakarta Struts ; John Wiley Husted, Ted;  Java Web Development With Struts ; Manning Spielman, Sue;  The Struts Framework: Practical Guide for Programmers ; Morgan Kaufman Turner, James;  Struts Kick Start ; Sams
Design Patterns Resources The Java Blueprints Web Site: http://java.sun.com/blueprints/ Design Patterns Books: Gamma, Erich (et. al.);  Design Patterns: Elements of Reusable Object-Oriented Software ; Addison-Wesley Alur, Deepak (et. al.);  Core J2EE Patterns: Best Practices and Design Strategies ; Prentice Hall
Q & A
Ad

More Related Content

What's hot (20)

Lecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworksLecture 05 web_applicationframeworks
Lecture 05 web_applicationframeworks
k. Nour el houda SLIMANI
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
Middleware Training
 
J2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for womenJ2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for women
lissa cidhi
 
J2 ee architecture
J2 ee architectureJ2 ee architecture
J2 ee architecture
Krishna Mer
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
Fahad Golra
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
Arun Vasanth
 
J2EE and layered architecture
J2EE and layered architectureJ2EE and layered architecture
J2EE and layered architecture
Suman Behara
 
Spring Framework -I
Spring Framework -ISpring Framework -I
Spring Framework -I
People Strategists
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
Prabhat gangwar
 
Mike Taulty MIX10 Silverlight 4 Patterns Frameworks
Mike Taulty MIX10 Silverlight 4 Patterns FrameworksMike Taulty MIX10 Silverlight 4 Patterns Frameworks
Mike Taulty MIX10 Silverlight 4 Patterns Frameworks
ukdpe
 
Naresh Kumar
Naresh KumarNaresh Kumar
Naresh Kumar
Naresh K
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Jdbc complete
Jdbc completeJdbc complete
Jdbc complete
Sandeep Rawat
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
jbashask
 
jdbc document
jdbc documentjdbc document
jdbc document
Yamuna Devi
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesChapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration Technologies
It Academy
 
Cs 1023 lec 2 (week 1) edit 1
Cs 1023  lec 2 (week 1) edit 1Cs 1023  lec 2 (week 1) edit 1
Cs 1023 lec 2 (week 1) edit 1
stanbridge
 
J2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for womenJ2EE PPT --CINTHIYA.M Krishnammal college for women
J2EE PPT --CINTHIYA.M Krishnammal college for women
lissa cidhi
 
J2 ee architecture
J2 ee architectureJ2 ee architecture
J2 ee architecture
Krishna Mer
 
Step by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts ApplicationStep by Step Guide for building a simple Struts Application
Step by Step Guide for building a simple Struts Application
elliando dias
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
Fahad Golra
 
24 collections framework interview questions
24 collections framework interview questions24 collections framework interview questions
24 collections framework interview questions
Arun Vasanth
 
J2EE and layered architecture
J2EE and layered architectureJ2EE and layered architecture
J2EE and layered architecture
Suman Behara
 
Mike Taulty MIX10 Silverlight 4 Patterns Frameworks
Mike Taulty MIX10 Silverlight 4 Patterns FrameworksMike Taulty MIX10 Silverlight 4 Patterns Frameworks
Mike Taulty MIX10 Silverlight 4 Patterns Frameworks
ukdpe
 
Naresh Kumar
Naresh KumarNaresh Kumar
Naresh Kumar
Naresh K
 
Database and Java Database Connectivity
Database and Java Database ConnectivityDatabase and Java Database Connectivity
Database and Java Database Connectivity
Gary Yeh
 
Java database connectivity
Java database connectivityJava database connectivity
Java database connectivity
Vaishali Modi
 
Struts Interview Questions
Struts Interview QuestionsStruts Interview Questions
Struts Interview Questions
jbashask
 
Jdbc (database in java)
Jdbc (database in java)Jdbc (database in java)
Jdbc (database in java)
Maher Abdo
 
Chapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration TechnologiesChapter 10:Understanding Java Related Platforms and Integration Technologies
Chapter 10:Understanding Java Related Platforms and Integration Technologies
It Academy
 
Cs 1023 lec 2 (week 1) edit 1
Cs 1023  lec 2 (week 1) edit 1Cs 1023  lec 2 (week 1) edit 1
Cs 1023 lec 2 (week 1) edit 1
stanbridge
 

Similar to Apachecon 2002 Struts (20)

Struts
StrutsStruts
Struts
s4al_com
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
Struts N E W
Struts N E WStruts N E W
Struts N E W
patinijava
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
JayaPrakash.m
 
MVC
MVCMVC
MVC
akshin
 
Struts Basics
Struts BasicsStruts Basics
Struts Basics
Harjinder Singh
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
Sunil Patil
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
Sunil Patil
 
Struts ppt 1
Struts ppt 1Struts ppt 1
Struts ppt 1
pavanteja86
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
s4al_com
 
Ibm
IbmIbm
Ibm
techbed
 
MVC 6 Introduction
MVC 6 IntroductionMVC 6 Introduction
MVC 6 Introduction
Sudhakar Sharma
 
Struts
StrutsStruts
Struts
Ranjan Kumar
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Beat Signer
 
Silverlight Development & The Model-View-ViewModel Pattern
Silverlight Development & The Model-View-ViewModel PatternSilverlight Development & The Model-View-ViewModel Pattern
Silverlight Development & The Model-View-ViewModel Pattern
Derek Novavi
 
Asp.net
Asp.netAsp.net
Asp.net
OpenSource Technologies Pvt. Ltd.
 
Skillwise Struts.x
Skillwise Struts.xSkillwise Struts.x
Skillwise Struts.x
Skillwise Group
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Julia Vi
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
Prashant Seth
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
Sunil Patil
 
D22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source FrameworksD22 Portlet Development With Open Source Frameworks
D22 Portlet Development With Open Source Frameworks
Sunil Patil
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
s4al_com
 
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Web Application Frameworks - Lecture 05 - Web Information Systems (4011474FNR)
Beat Signer
 
Silverlight Development & The Model-View-ViewModel Pattern
Silverlight Development & The Model-View-ViewModel PatternSilverlight Development & The Model-View-ViewModel Pattern
Silverlight Development & The Model-View-ViewModel Pattern
Derek Novavi
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Julia Vi
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
Prashant Seth
 
Ad

Recently uploaded (20)

Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
tecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdftecnologias de las primeras civilizaciones.pdf
tecnologias de las primeras civilizaciones.pdf
fjgm517
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Ad

Apachecon 2002 Struts

  • 1. Building Web Applications With The Struts Framework Session WE06 – 11/20/2002 – 10:00-11:00 Craig R. McClanahan Senior Staff Engineer Sun Microsystems, Inc.
  • 2. Session Outline Web Applications Backgrounder The Model-View-Controller Architecture The Struts Framework Building A Web Application With Struts Resources
  • 4. Web Applications Backgrounder Web applications run over the HTTP protocol: Request/response oriented Stateless Web applications use varied presentation (markup) languages, and talk to varied client hardware devices: “ Standard HTML” -- not! Varying dynamic and JavaScript capabilities Wireless devices vary in capabilities, language dialect, and input device support
  • 5. Simple Solutions ... for Simple Problems For relatively simple applications, a simple architecture works fine For each page in the user interface ... Create a servlet, JSP page, or something similar The page includes: Logic to create the user interface Logic to retrieve required information from the database Logic to perform the appropriate business transaction Logic to update the corresponding database information And it's all mixed together in one source file This works fine for a Guest Book app, but what about something bigger?
  • 6. What About Large Scale Applications? Disparate skill sets required: Presentation Layer -- User interface design, visual appearance, interaction model Application Layer – Functional business logic to perform required transactions Persistence Layer – Databases, directory servers, messaging, Enterprise JavaBeans TM (EJBs) Application Deployment – Networks, firewalls, public key infrastructures, load balancing, failover We need a fundamental organizing principle: The Model-View-Controller (MVC) architecture
  • 8. The Model-View-Controller Architecture Divides the overall functionality of an application into three layers: Model Layer – Contains the functional business logic of the application, as well as a representation of the persistently stored data backing the application View Layer – Contains the user interface, including mechanisms to accept user input and render results Controller Layer – Contains the logic that manages the flow of individual requests, dispatching to the appropriate business logic component
  • 9. The Model Layer Functional business logic: Should be modelled as JavaBeans or Session EJBs Should be reusable in non-web environments API exposes public methods for each logical unit of work (while hiding the details) Persistent data storage: Should manage permanent storage of application data Typically shared across many applications API should expose data retrieval and storage operations (while hiding the mechanisms)
  • 10. The View Layer Creation of the user interface: Typically in HTML or an XML-based dialect Normally a combination of static and dynamic content Actual content varies depending on: Device or browser type User preferences / personalization Internationalization and localization requirements Accessibility requirements
  • 11. The Controller Layer Incoming requests flow through a common path: Received by common component Standardized request pre-processing Dispatch to request-specific model component (business logic) Forward to business-logic-specified view component Standardized request post-processing Often called “Model 2 Design” in the JSP/Servlet community In modern design pattern terminology, Struts implements the front controller pattern.
  • 12. The Struts Framework – An Implementation of the MVC Architecture
  • 13. The Struts Framework – Architecture
  • 14. The Struts Framework – Model Layer Struts does not restrict implementation techniques for model layer JDBC-accessed databases Enterprise JavaBeans O-R mapping tools Optional JDBC connection pool available Common design pattern: Action acquires information from persistence tier Exposes information as request/session attributes View layer pulls data from attributes for display
  • 15. The Struts Framework – View Layer Form Bean maintains state of form input fields across requests: ActionForm – Standard JavaBean design pattern DynaActionForm – Property names and types defined in Struts configuration file In addition to properties, form beans define two standard methods: reset() -- Reset form properties to initial state validate() -- Perform field-level validations Form bean properties are typically Strings Allows redisplay of invalid input
  • 16. The Struts Framework – View Layer Internationalization Support enables locale-specific applications Locale – Standard Java class representing a choice of language and/or country MessageFormat – Standard Java class representing an individual message with replaceable parameters: “ {0} is not a valid credit rating” MessageResources – Struts abstraction around sets of messages for supported locales ActionErrors / ActionMessages – Struts collections of localized messages
  • 17. The Struts Framework – View Layer JSP Custom Tag Libraries – If you are using JSP pages for your presentation struts-bean.tld – Fundamental bean manipulation and internationalization struts-html.tld – “Smart” HTML elements struts-logic.tld – Basic conditionals and iteration struts-template.tld – Basic layout management
  • 18. The Struts Framework – View Layer Standard tag libraries added in Struts 1.1: struts-nested.tld -- “Nested” variants of standard tags that resolve relative references against beans struts-tiles.tld – Full features layout management library Contributed libraries added in Struts 1.1: struts-xxx-el.tld – Versions of standard Struts tag libraries that support the expression language syntax of JSP Standard Tag Library
  • 19. The Struts Framework – View Layer Validation Framework No-code-required field level validations Configured in an XML document included in the web application Optionally generates client side JavaScript to enforce validation rules Extensible architecture
  • 20. The Struts Framework – Controller Layer ActionServlet – Standard implementation of controller At application startup, reads configuration file and initializes resources [Struts 1.1] PlugIn – General start/stop hook On each request, implements the standard Struts request processing lifecycle (in Struts 1.1, implemented in RequestProcessor ) Specialization / customization via subclassing [Struts 1.1] Sub-application modules support
  • 21. The Struts Framework – Controller Layer Action – Standard base class for business logic components and adapters: Mapped to logical names by request processor Single instance per application (must be thread safe) Instantiated as needed, like servlets Implements the “Command Pattern” execute() -- Invoked for each request Can (but typically does not) create response content directly Typically returns ActionForward to select resource to prepare response
  • 22. The Struts Framework – Controller Layer Standard Request Processing Lifecycle 1: processLocale() -- Record user's locale preference (if not already present) processPreprocess() -- general purpose pre-processing hook processMapping() -- select Action to be utilized processRoles() -- perform security role-based restrictions on action execution processActionForm() -- Create or acquire an appropriate ActionForm instance
  • 23. The Struts Framework – Controller Layer Standard Request Processing Lifecycle 2: processPopulate() -- Copy the request parameters into the form bean properties processValidate() -- Call form bean's validate() method processActionCreate() -- Create or acquire an appropriate Action instance processActionPerform() -- Call action's execute() method processActionForward() -- Process returned ActionForward instance (if any)
  • 24. The Struts Framework – Controller Layer XML Configuration Document (/WEB-INF/struts-config.xml) Standard place to configure all aspects of the application's behavior DTD included for optional (but recommended) validation Logical-to-physical mappings for Actions, ActionForms, and ActionForwards General configuration settings [Struts 1.1] Configuration Document per module if more than one
  • 25. The Struts Framework – Commons Libraries Non-Struts Specific Logic Factored Out: commons-beanutils – Generic bean property manipulation commons-collections – Extensions to standard Java2 collections classes commons-dbcp – Optional JDBC connection pool commons-digester – XML parsing for configuration files commons-fileupload – Support library for HTML file uploads
  • 26. The Struts Framework – Commons Libraries Non-Struts Specific Logic Factored Out: commons-logging – Application logging wrapper commons-pool – Object pooling library commons-resources – Message resources support library Commons-validator – Field validation framework
  • 28. Building Web Applications With Struts Now that we understand the architecture of Struts, let's look at parts of an example app that is built with it Struts includes a canonical example that is useful in determining whether you have installed things correctly struts-example.war Application models (part of) an email portal site that lets you maintain multiple subscriptions
  • 29. Sample Application – Model Layer (Persistence Tier) Modelled via a Data Access Object (DAO) org.apache.struts.webapp.example.UserDatabase public interface UserDatabase { public User createUser(String username); public void close() throws Exception; public User findUser(String username); public User[] findUsers(); public void open() throws Exception; public void removeUser(User user); public void save() throws Exception; }
  • 30. Sample Application – Model Layer (Persistence Tier) Default implementation based on loading an XML document into memory: o.a.s.e.memory.MemoryUserDatabase JDBC-based (or LDAP-based) implementation is easy to imagine, and would be transparent to the business logic Implementation selection implemented via a PlugIn ... see configuration file example later
  • 31. Sample Application – Model Layer (Business Logic) Two common Struts design patterns illustrated View --> View --> Action Welcome Page has link to logon page: <html:link page=”/logon.jsp”>...</html:link> Logon page instantiates LogonForm bean Form submit goes to “/logon” action View --> Action --> View --> Action Setup action “/editRegistration?action=Edit” pulls data from “database” and populates form bean Registration page “ /registration.jsp” displays current data Form submit goes to “/saveRegistration” action
  • 32. Sample Application – View Layer (logon.jsp) <%@ page contentType=”text/html;charset=”UTF-8” %> <%@ taglib uri=”/WEB-INF/struts-bean.tld” prefix=” bean ” %> <%@ taglib uri=”/WEB-INF/struts-html.tld” prefix=” html ” %> < html:html locale=”true”> <head> <title> < bean:message key=”logon.title”/> </title> < html:base /> </head>
  • 33. Sample Application – View Layer (logon.jsp) <body bgcolor=”white”> < html:errors /> < html:form action=”/logon” focus=”username” onsubmit=”return validateLogonForm(this);”> <table border=”0” width=”100%”> <tr> <th align=”right”> < bean:message key=”prompt.username”/> </th> <td align=”left”> < html:text property=”username” size=”16”/> </td> </tr>
  • 34. Sample Application – View Layer (logon.jsp) <tr> <th align=”right”> < bean:message key=”prompt.password”/> </th> <td align=”left”> < html:password property=”password” size=”16”/> </td> </tr> </table></ html:form > < html:javascript formName=”logonForm” dynamicJavascript=”true” staticJavascript=”false”/> <script language=”Javascript” .../> </body></ html:html >
  • 35. Sample Application – Controller Layer No application logic required – Struts does everything for you :-) Controller functionality is configured via XML-based files: struts-config.xml – Struts controller configuration validation.xml – Validator framework configuration web.xml – Web application configuration
  • 36. Sample Application – Struts Configuration (struts-config.xml) <struts-config> <form-beans> ... <form-bean name=”logonForm” type=” org.apache.struts.action.DynaActionForm ”> <form-property name=”username” type=” java.lang.String ”/> <form-property name=”password” type=” java.lang.String ”/> </form-bean> <form-bean name=”registrationForm” type=” org.apache.webapp.example.RegistrationForm ”/> ... </form-beans>
  • 37. Sample Application – Struts Configuration (struts-config.xml) <global-forwards> <forward name=”logoff” path=”/logoff.do”/> <forward name=”logon” path=”/logon.do”/> <forward name=”registration” path=”/registration.jsp”/> <forward name=”success” path=”/mainMenu.jsp”/> </global-forwards>
  • 38. Sample Application – Struts Configuration (struts-config.xml) <action-mappings> <action path=” /editRegistration ” type=” org.apache.struts.webapp.example.EditRegistrationAction ” name=”registrationForm” scope=”request” validate=”false”> <forward name=”success” path=”/registration.jsp”/> </action> <action path=” /saveRegistration ” type=” org.apache.struts.webapp.example.SaveRegistrationAction ” name=”registrationForm” scope=”request” validate=”true” input=”registration”/>
  • 39. Sample Application – Struts Configuration (struts-config.xml) <action path=” /logon ” type=” org.apache.struts.webapp.example.LogonAction ” input=”request” name=”logonForm” scope=”request”/> ... </action-mappings> <controller> <set-property property=”inputForward” value=”true”/> </controller> <message-resources parameter=” org.apache.struts.example.ApplicationResources ”/>
  • 40. Sample Application – Struts Configuration (struts-config.xml) <plug-in className=” org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn ”> <set-property property=”pathname” value=”/WEB-INF/database.xml”/> </plug-in> <plug-in className=” org.apache.struts.validator.ValidatorPlugIn ”> <set-property property=”pathnames” value=”/WEB-INF/validator-rules.xml, /WEB-INF/validation.xml”/> </plug-in> </struts-config>
  • 41. Sample Application – Struts Configuration (validation.xml) <form-validation> <formset> <form name=” logonForm ”> <field property=”username” depends=”minlength,...”> <arg0 key=”prompt.username”/> <arg1 key=”${var:minlength}” name=”minlength” resource=”false”/> <var><var-name>minlength</var-name> <var-value>3</var-value></var> ... </field> ... </form> ... </formset> </form-validation>
  • 42. Sample Application – Webapp Configuration (web.xml) <web-app> <servlet> <servlet-name>Controller</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/struts-config.xml </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet>
  • 43. Sample Application – Webapp Configuration (web.xml) <servlet-mapping> <servlet-name>Controller</servlet-name> <url-pattern> *.do </url-pattern> </servlet-mapping> ... </web-app>
  • 45. Struts 1.1 Release When? “Real Soon Now” What new features? Apache Commons Libraries DynaActionForm Declarative Exception Handling Nested Tag Library PlugIn API Sub-Application Module Support (Contributed) STRUTS-EL Tag Libraries
  • 46. Struts and JSTL JSP Standard Tag Library (JSTL) 1.0: Expression language (“${customer.address[“mailing”].city”) General purpose actions (out, set, remove, catch) Conditional actions (if, choose, when, otherwise) Iterator actions (forEach, forTokens) URL actions (import, url, redirect, param) Internationalization actions (message, setLocale, bundle, setBundle, message, param, requestEncoding) Formatting actions (timeZone, setTimeZone, formatNumber, parseNumber, formatDate, parseDate)
  • 47. Struts and JSTL JSP Standard Tag Library (JSTL) 1.0, continued: SQL actions (not relevant in an MVC framework environment) XML core actions (parse, out, set) XML flow control actions (if, choose, when, otherwise, forEach) XML transform actions (transform, param) The struts-xxx-el libraries are a bridge for Struts developers who want to leverage JSTL tags, and expression language syntax, now
  • 48. Struts and JSF JavaServer Faces (currently under development in JSR-127) Goals: Standard GUI component framework for web applications RenderKits for different rendering environments (browser vs. wireless device, different locales, etc.) Struts will provide an integration library: Requires changes to view layer and struts-config.xml file only ! Plugs in to RequestProcessor APIs
  • 50. This Presentation Online StarOffice 6.0: http://www.apache.org/~craigmcc/apachecon-2002-struts.sxi Powerpoint: http://www.apache.org/~craigmcc/apachecon-2002-struts.ppt
  • 51. Internet Technologies Hypertext Markup Language (HTML) 4.01: http://www.w3.org/TR/html4/ Hypertext Transfer Protocol (HTTP) 1.1: http://www.ietf.org/rfc/rfc2616.txt Uniform Resource Identifiers (URI): http://www.ietf.org/rfc/rfc2396.txt
  • 52. Model Layer – Standard Java APIs JavaBeans: http://java.sun.com/products/javabeans/ Java Database Connectivity (JDBC): http://java.sun.com/products/jdbc/ Java Data Objects: http://java.sun.com/products/jdo/ http://jcp.org/jsr/detail/12.jsp Java Naming and Directory Interface: http://java.sun.com/products/jndi/ Enterprise JavaBeans (EJB): http://java.sun.com/products/ejb/
  • 53. Model Layer – Persistence Frameworks Castor: http://castor.exolab.org/ Java Data Objects: http://java.sun.com/products/jdo/ Object/Relational Bridge: http://jakarta.apache.org/ojb/ Torque: http://jakarta.apache.org/turbine/torque/
  • 54. View Layer – Standard Java APIs Servlets: http://java.sun.com/products/servlet/ JavaServer Pages (JSP): http://java.sun.com/products/jsp/ JSP Standard Tag Library (JSTL): http://java.sun.com/products/jsp/jstl/ JavaServer Faces: http://java.sun.com/j2ee/javaserverfaces/ http://jcp.org/jsr/detail/127.jsp
  • 55. Struts Resources The Struts and Commons Web Sites: http://jakarta.apache.org/struts/ http://jakarta.apache.org/commons/ Recent Books About Struts: Cavaness, Chuck; Programming Jakarta Struts ; O'Reilly Goodwill, James; Mastering Jakarta Struts ; John Wiley Husted, Ted; Java Web Development With Struts ; Manning Spielman, Sue; The Struts Framework: Practical Guide for Programmers ; Morgan Kaufman Turner, James; Struts Kick Start ; Sams
  • 56. Design Patterns Resources The Java Blueprints Web Site: http://java.sun.com/blueprints/ Design Patterns Books: Gamma, Erich (et. al.); Design Patterns: Elements of Reusable Object-Oriented Software ; Addison-Wesley Alur, Deepak (et. al.); Core J2EE Patterns: Best Practices and Design Strategies ; Prentice Hall
  • 57. Q & A