SlideShare a Scribd company logo
Web Development with
                                Apache Struts 2

                                Fabrizio Giudici

                                Tidalwave sas, CEO
                                NetBeans Dream Team

                                Senior Java Architect, Blogger


                                www.tidalwave.it
                                bluemarine.tidalwave.it
                                weblogs.java.net/blog/fabriziogiudici
                                stoppingdown.net




Nov 20, 2008   Web Development with Apache Struts 2                     1
Agenda
               ●   Java Web Frameworks
               ●   Struts basics
               ●   Struts 2
               ●   A small code example
               ●   Q&A




Nov 20, 2008             Web Development with Apache Struts 2        2
NetBeans 6.5 is out
               ●   Get it while it's hot! www.netbeans.org
                      –   Faster!
                      –   Compile-on-save, multithreading Java
                           debugger, visual deadlock indication
                      –   PHP support, JavaScript debugger and
                           library manager, better Spring /
                           Hibernate / JSF / JPA support
                      –   RESTful web services, SQL editor
                           improvements, JavaFX, Groovy and
                           Grails, Ruby and Rails improvements,
                           GlassFish v3
               ●
Nov 20, 2008               Web Development with Apache Struts 2   3
Java Web Frameworks
               ●   Question: how many Java web
                   frameworks are available?
                      –   1?
                      –   5?
                      –   10?
                      –   Dozens?




Nov 20, 2008              Web Development with Apache Struts 2   4
Java Web Frameworks
               ●   Answer: more than 50!
                       –   www.manageability.org/blog/stuff/how-
                            many-java-web-frameworks
               ●   Of course, those with a significant
                   spread are not so many
               ●   But choosing is difficult
               ●   NIH, but also radically different
                   approaches


Nov 20, 2008               Web Development with Apache Struts 2    5
My (subjective) take
               ●   Wicket
                       –   You really want to be agile
                       –   You routinely live on the leading edge
               ●   Tapestry
                       –   You like agile, but consolidated
               ●   Struts
                       –   You are “conservative” and like it easy
               ●   Java Server Faces
                       –   You love visual designers
                       –   You can survive to high complexity
Nov 20, 2008                Web Development with Apache Struts 2     6
JEE
               ●   JEE Web components:
                      –   “Foundation”: Servlet, JSP, Filter
                      –   “High level”: JSF
               ●   Foundation elements are enough, but
                   you're going to write tons of code
                      –   Validation, flow control, etc...




Nov 20, 2008               Web Development with Apache Struts 2     7
Struts
               ●   Struts 1 appeared in June 2001
                       –   Apache License
                       –   Strictly based on MVC pattern
                       –   Supported declarative validation, flow
                            control
               ●   Struts 2 is the “merge” of Struts 1 +
                   WebWork




Nov 20, 2008                Web Development with Apache Struts 2        8
MVC




Nov 20, 2008   Web Development with Apache Struts 2     9
Struts 2.x benefits
               ●   Actions are POJOs
               ●   Interceptors (from AOP)
               ●   Classes are now independent of HTTP
               ●   Simplified testing
               ●   Annotations, AJAX, Spring, Portlets,
                   etc...




Nov 20, 2008             Web Development with Apache Struts 2   10
Workflow




Nov 20, 2008   Web Development with Apache Struts 2          11
Components
               ●   web.xml
                      –   Installs a Filter on /*
               ●   struts.xml
                      –   Maps Action names
                      –   Defines the navigation flow
               ●   Actions
                      –   Execute a task
               ●   Views (JSP or others)
                      –   Render the UI
Nov 20, 2008               Web Development with Apache Struts 2     12
web.xml
               <?xml version="1.0" encoding="UTF-8"?>
               <web-app ... >
                   <filter>
                       <filter-name>struts2</filter-name>
                       <filter-class>
                           org.apache.struts2.dispatcher.FilterDispatcher
                       </filter-class>
                   </filter>
                   <filter-mapping>
                       <filter-name>struts2</filter-name>
                       <url-pattern>/*</url-pattern>
                   </filter-mapping>

                  ...

               </web-app>




Nov 20, 2008                Web Development with Apache Struts 2         13
A simple Action
         import com.opensymphony.xwork2.ActionSupport;

         public class MyAction extends ActionSupport {
             private final List<String> NBDTers = Arrays.asList(...);

               private String userName;
               private String message;

               public String getUserName() { return userName; }

               public void setUserName(String userName) {
                   this.userName = userName;
               }

               public String getMessage() { return message; }

               @Override
               public String execute() {
                   message = userName;
                   return NBDTers.contains(userName) ? "nbdt" : SUCCESS;
               }
          }
Nov 20, 2008                 Web Development with Apache Struts 2          14
struts.xml


               <struts>

                  <package name="/" extends="struts-default">
                    <action name="MyAction" class="myexample.MyAction">
                       <result name="input">/index.jsp</result>
                       <result name="success">/good.jsp</result>
                       <result name="nbdt">/nbdt.jsp</result>
                    </action>
                 </package>

               </struts>




Nov 20, 2008                 Web Development with Apache Struts 2            15
A simple view JSP
               <%@page contentType="text/html" pageEncoding="UTF-8"%>
               <%@taglib prefix="s" uri="/struts-tags" %>

               <html>
                 <body>
                   <h2>Welcome to JUG Lugano</h2>
                     Hello, <s:property value="message" default="Guest" />,
                      welcome to the first meeting of JUG Lugano!
                     <s:form method="GET" action="MyAction.action">
                        Would you be so kind to tell me your name?
                        <s:textfield name="userName" />
                        <s:submit value="Submit" />
                     </s:form>

                     <s:actionerror/>
                     <s:fielderror/>
                 </body>
               </html>


Nov 20, 2008                    Web Development with Apache Struts 2          16
Interceptors
               ●   Used to implement “common”
                   behaviours
                      –   Validations
                      –   Multiple submit filters
                      –   Logging
               ●   Pre-defined interceptors




Nov 20, 2008               Web Development with Apache Struts 2         17
Formal validation
                 ●    Declarative, save tons of code

               <validators>

                     <field name="userName">
                         <field-validator type="requiredstring">
                             <param name="trim">true</param>
                             <message>Your name is required.</message>
                         </field-validator>
                     </field>

               </validators>




Nov 20, 2008                   Web Development with Apache Struts 2      18
Interceptors
               ●   Code that is invoked across Actions
               ●   Many pre-defined interceptors
                      –   Parameter rename, cookie
                           management, component behaviours
                           (e.g. Checkboxes), background
                           actions
                      –   Validation itself is an interceptor




Nov 20, 2008               Web Development with Apache Struts 2         19
Custom interceptors


               public interface Interceptor
                 extends Serializable
                 {
                   public void destroy();

                    public void init();

                    public String intercept (ActionInvocation inv)
                       throws Exception;
                }




Nov 20, 2008                   Web Development with Apache Struts 2   20
Interceptors in
                                                            struts.xml

               <struts>

                  <package name="/" extends="struts-default">
                       <interceptors>
                           <interceptor name="logger" class="..."/>
                       </interceptors>
                    <action name="MyAction" class="myexample.MyAction">
                       <interceptor-ref name="logger"/>
                       <result name="success">/good.jsp</result>
                       <result name="nbdt">/nbdt.jsp</result>
                       <result name="input">/index.jsp</result>
                    </action>
                 </package>

               </struts>


Nov 20, 2008                 Web Development with Apache Struts 2         21
Conclusion
               ●   Robust, Struts 1 heritage
               ●   Keeps up with the latest standards
                   (POJOs, AOP, annotations, Spring, ...)
               ●   “Conservative” approach, but easy
               ●   Relevant sites:
                       –   struts.apache.org
                       –   beans.seartipy.com/2008/08/04/struts-
                            2-plugin-for-netbeans-ide-
                            nbstruts2support/

Nov 20, 2008               Web Development with Apache Struts 2       22

More Related Content

Viewers also liked

Bai 09 Basic jsp
Bai 09 Basic jspBai 09 Basic jsp
Bai 09 Basic jsp
Hà Huy Hoàng
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
Emprovise
 
Struts2.x
Struts2.xStruts2.x
Struts2.x
Sandeep Rawat
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
wiradikusuma
 
Struts2
Struts2Struts2
Struts2
Rajiv Gupta
 
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and WicketComparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Matt Raible
 

Viewers also liked (9)

Bai 09 Basic jsp
Bai 09 Basic jspBai 09 Basic jsp
Bai 09 Basic jsp
 
Lecture6
Lecture6Lecture6
Lecture6
 
Struts2 in a nutshell
Struts2 in a nutshellStruts2 in a nutshell
Struts2 in a nutshell
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
 
Struts2.x
Struts2.xStruts2.x
Struts2.x
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Struts
StrutsStruts
Struts
 
Struts2
Struts2Struts2
Struts2
 
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and WicketComparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
Comparing JSF, Spring MVC, Stripes, Struts 2, Tapestry and Wicket
 

Similar to Web Development with Apache Struts 2

The Java alternative to Javascript
The Java alternative to JavascriptThe Java alternative to Javascript
The Java alternative to Javascript
Manuel Carrasco Moñino
 
GlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and FutureGlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and Future
Alexis Moussine-Pouchkine
 
Java EE 6 & GlassFish v3: Paving path for the future
Java EE 6 & GlassFish v3: Paving path for the futureJava EE 6 & GlassFish v3: Paving path for the future
Java EE 6 & GlassFish v3: Paving path for the future
Arun Gupta
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjsPeter Edwards
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
PawanMM
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
Hitesh-Java
 
Comparing JVM Web Frameworks - Devoxx 2010
Comparing JVM Web Frameworks - Devoxx 2010Comparing JVM Web Frameworks - Devoxx 2010
Comparing JVM Web Frameworks - Devoxx 2010
Matt Raible
 
Java EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexusJava EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexus
Arun Gupta
 
Java EE 6 : Paving The Path For The Future
Java EE 6 : Paving The Path For The FutureJava EE 6 : Paving The Path For The Future
Java EE 6 : Paving The Path For The Future
IndicThreads
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13Fred Sauer
 
Spark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 WorkshopSpark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 Workshop
Arun Gupta
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MIT
jeresig
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
jeresig
 
Present and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectivePresent and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspective
Manuel Carrasco Moñino
 
Struts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web ApplicationsStruts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web Applications
JavaEE Trainers
 
Net Beans61 Ide
Net Beans61 IdeNet Beans61 Ide
Net Beans61 Ide
satyajit_t
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010
Arun Gupta
 
Skillwise Struts.x
Skillwise Struts.xSkillwise Struts.x
Skillwise Struts.x
Skillwise Group
 
Real Time Web - What's that for?
Real Time Web - What's that for?Real Time Web - What's that for?
Real Time Web - What's that for?Martyn Loughran
 

Similar to Web Development with Apache Struts 2 (20)

The Java alternative to Javascript
The Java alternative to JavascriptThe Java alternative to Javascript
The Java alternative to Javascript
 
GlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and FutureGlassFish and JavaEE, Today and Future
GlassFish and JavaEE, Today and Future
 
Java EE 6 & GlassFish v3: Paving path for the future
Java EE 6 & GlassFish v3: Paving path for the futureJava EE 6 & GlassFish v3: Paving path for the future
Java EE 6 & GlassFish v3: Paving path for the future
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjs
 
Session 41 - Struts 2 Introduction
Session 41 - Struts 2 IntroductionSession 41 - Struts 2 Introduction
Session 41 - Struts 2 Introduction
 
Struts 2 - Introduction
Struts 2 - Introduction Struts 2 - Introduction
Struts 2 - Introduction
 
Comparing JVM Web Frameworks - Devoxx 2010
Comparing JVM Web Frameworks - Devoxx 2010Comparing JVM Web Frameworks - Devoxx 2010
Comparing JVM Web Frameworks - Devoxx 2010
 
Java EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexusJava EE 6 & GlassFish v3 @ DevNexus
Java EE 6 & GlassFish v3 @ DevNexus
 
Java EE 6 : Paving The Path For The Future
Java EE 6 : Paving The Path For The FutureJava EE 6 : Paving The Path For The Future
Java EE 6 : Paving The Path For The Future
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
 
Spark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 WorkshopSpark IT 2011 - Java EE 6 Workshop
Spark IT 2011 - Java EE 6 Workshop
 
Learning jQuery @ MIT
Learning jQuery @ MITLearning jQuery @ MIT
Learning jQuery @ MIT
 
JavaScript Library Overview
JavaScript Library OverviewJavaScript Library Overview
JavaScript Library Overview
 
Present and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectivePresent and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspective
 
Struts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web ApplicationsStruts2 course chapter 1: Evolution of Web Applications
Struts2 course chapter 1: Evolution of Web Applications
 
Net Beans61 Ide
Net Beans61 IdeNet Beans61 Ide
Net Beans61 Ide
 
Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010Powering the Next Generation Services with Java Platform - Spark IT 2010
Powering the Next Generation Services with Java Platform - Spark IT 2010
 
Skillwise Struts.x
Skillwise Struts.xSkillwise Struts.x
Skillwise Struts.x
 
Real Time Web - What's that for?
Real Time Web - What's that for?Real Time Web - What's that for?
Real Time Web - What's that for?
 
Struts2
Struts2Struts2
Struts2
 

More from Fabrizio Giudici

Building Android apps with Maven
Building Android apps with MavenBuilding Android apps with Maven
Building Android apps with Maven
Fabrizio Giudici
 
DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011 DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011
Fabrizio Giudici
 
DCI - Data, Context and Interaction @ Jug Genova April 2011
DCI - Data, Context and Interaction @ Jug Genova April 2011DCI - Data, Context and Interaction @ Jug Genova April 2011
DCI - Data, Context and Interaction @ Jug Genova April 2011
Fabrizio Giudici
 
NOSQL also means RDF stores: an Android case study
NOSQL also means RDF stores: an Android case studyNOSQL also means RDF stores: an Android case study
NOSQL also means RDF stores: an Android case studyFabrizio Giudici
 
Tools for an effective software factory
Tools for an effective software factoryTools for an effective software factory
Tools for an effective software factoryFabrizio Giudici
 
Parallel Computing Scenarios and the new challenges for the Software Architect
Parallel Computing Scenarios  and the new challenges for the Software ArchitectParallel Computing Scenarios  and the new challenges for the Software Architect
Parallel Computing Scenarios and the new challenges for the Software ArchitectFabrizio Giudici
 
blueMarine a desktop app for the open source photographic workflow
blueMarine  a desktop app for the open source photographic workflowblueMarine  a desktop app for the open source photographic workflow
blueMarine a desktop app for the open source photographic workflowFabrizio Giudici
 
blueMarine photographic workflow with Java
blueMarine photographic workflow with JavablueMarine photographic workflow with Java
blueMarine photographic workflow with JavaFabrizio Giudici
 
blueMarine Sailing with NetBeans Platform
blueMarine Sailing with NetBeans PlatformblueMarine Sailing with NetBeans Platform
blueMarine Sailing with NetBeans PlatformFabrizio Giudici
 
NASA World Wind for Java API Overview
NASA World Wind for Java  API OverviewNASA World Wind for Java  API Overview
NASA World Wind for Java API OverviewFabrizio Giudici
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans Fabrizio Giudici
 
blueMarine Or Why You Should Really Ship Swing Applications
blueMarine  Or Why You Should Really Ship Swing  Applications blueMarine  Or Why You Should Really Ship Swing  Applications
blueMarine Or Why You Should Really Ship Swing Applications Fabrizio Giudici
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile applicationFabrizio Giudici
 
Android java fx-jme@jug-lugano
Android java fx-jme@jug-luganoAndroid java fx-jme@jug-lugano
Android java fx-jme@jug-lugano
Fabrizio Giudici
 

More from Fabrizio Giudici (17)

Building Android apps with Maven
Building Android apps with MavenBuilding Android apps with Maven
Building Android apps with Maven
 
DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011 DCI - Data, Context and Interaction @ Jug Lugano May 2011
DCI - Data, Context and Interaction @ Jug Lugano May 2011
 
DCI - Data, Context and Interaction @ Jug Genova April 2011
DCI - Data, Context and Interaction @ Jug Genova April 2011DCI - Data, Context and Interaction @ Jug Genova April 2011
DCI - Data, Context and Interaction @ Jug Genova April 2011
 
NOSQL also means RDF stores: an Android case study
NOSQL also means RDF stores: an Android case studyNOSQL also means RDF stores: an Android case study
NOSQL also means RDF stores: an Android case study
 
Netbeans+platform+maven
Netbeans+platform+mavenNetbeans+platform+maven
Netbeans+platform+maven
 
Tools for an effective software factory
Tools for an effective software factoryTools for an effective software factory
Tools for an effective software factory
 
Parallel Computing Scenarios and the new challenges for the Software Architect
Parallel Computing Scenarios  and the new challenges for the Software ArchitectParallel Computing Scenarios  and the new challenges for the Software Architect
Parallel Computing Scenarios and the new challenges for the Software Architect
 
blueMarine a desktop app for the open source photographic workflow
blueMarine  a desktop app for the open source photographic workflowblueMarine  a desktop app for the open source photographic workflow
blueMarine a desktop app for the open source photographic workflow
 
blueMarine photographic workflow with Java
blueMarine photographic workflow with JavablueMarine photographic workflow with Java
blueMarine photographic workflow with Java
 
blueMarine Sailing with NetBeans Platform
blueMarine Sailing with NetBeans PlatformblueMarine Sailing with NetBeans Platform
blueMarine Sailing with NetBeans Platform
 
NASA World Wind for Java API Overview
NASA World Wind for Java  API OverviewNASA World Wind for Java  API Overview
NASA World Wind for Java API Overview
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 
The VRC Project
The VRC ProjectThe VRC Project
The VRC Project
 
blueMarine Or Why You Should Really Ship Swing Applications
blueMarine  Or Why You Should Really Ship Swing  Applications blueMarine  Or Why You Should Really Ship Swing  Applications
blueMarine Or Why You Should Really Ship Swing Applications
 
Designing a JavaFX Mobile application
Designing a JavaFX Mobile applicationDesigning a JavaFX Mobile application
Designing a JavaFX Mobile application
 
Android java fx-jme@jug-lugano
Android java fx-jme@jug-luganoAndroid java fx-jme@jug-lugano
Android java fx-jme@jug-lugano
 
Mercurial
MercurialMercurial
Mercurial
 

Recently uploaded

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

Web Development with Apache Struts 2

  • 1. Web Development with Apache Struts 2 Fabrizio Giudici Tidalwave sas, CEO NetBeans Dream Team Senior Java Architect, Blogger www.tidalwave.it bluemarine.tidalwave.it weblogs.java.net/blog/fabriziogiudici stoppingdown.net Nov 20, 2008 Web Development with Apache Struts 2 1
  • 2. Agenda ● Java Web Frameworks ● Struts basics ● Struts 2 ● A small code example ● Q&A Nov 20, 2008 Web Development with Apache Struts 2 2
  • 3. NetBeans 6.5 is out ● Get it while it's hot! www.netbeans.org – Faster! – Compile-on-save, multithreading Java debugger, visual deadlock indication – PHP support, JavaScript debugger and library manager, better Spring / Hibernate / JSF / JPA support – RESTful web services, SQL editor improvements, JavaFX, Groovy and Grails, Ruby and Rails improvements, GlassFish v3 ● Nov 20, 2008 Web Development with Apache Struts 2 3
  • 4. Java Web Frameworks ● Question: how many Java web frameworks are available? – 1? – 5? – 10? – Dozens? Nov 20, 2008 Web Development with Apache Struts 2 4
  • 5. Java Web Frameworks ● Answer: more than 50! – www.manageability.org/blog/stuff/how- many-java-web-frameworks ● Of course, those with a significant spread are not so many ● But choosing is difficult ● NIH, but also radically different approaches Nov 20, 2008 Web Development with Apache Struts 2 5
  • 6. My (subjective) take ● Wicket – You really want to be agile – You routinely live on the leading edge ● Tapestry – You like agile, but consolidated ● Struts – You are “conservative” and like it easy ● Java Server Faces – You love visual designers – You can survive to high complexity Nov 20, 2008 Web Development with Apache Struts 2 6
  • 7. JEE ● JEE Web components: – “Foundation”: Servlet, JSP, Filter – “High level”: JSF ● Foundation elements are enough, but you're going to write tons of code – Validation, flow control, etc... Nov 20, 2008 Web Development with Apache Struts 2 7
  • 8. Struts ● Struts 1 appeared in June 2001 – Apache License – Strictly based on MVC pattern – Supported declarative validation, flow control ● Struts 2 is the “merge” of Struts 1 + WebWork Nov 20, 2008 Web Development with Apache Struts 2 8
  • 9. MVC Nov 20, 2008 Web Development with Apache Struts 2 9
  • 10. Struts 2.x benefits ● Actions are POJOs ● Interceptors (from AOP) ● Classes are now independent of HTTP ● Simplified testing ● Annotations, AJAX, Spring, Portlets, etc... Nov 20, 2008 Web Development with Apache Struts 2 10
  • 11. Workflow Nov 20, 2008 Web Development with Apache Struts 2 11
  • 12. Components ● web.xml – Installs a Filter on /* ● struts.xml – Maps Action names – Defines the navigation flow ● Actions – Execute a task ● Views (JSP or others) – Render the UI Nov 20, 2008 Web Development with Apache Struts 2 12
  • 13. web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app ... > <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> ... </web-app> Nov 20, 2008 Web Development with Apache Struts 2 13
  • 14. A simple Action import com.opensymphony.xwork2.ActionSupport; public class MyAction extends ActionSupport { private final List<String> NBDTers = Arrays.asList(...); private String userName; private String message; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getMessage() { return message; } @Override public String execute() { message = userName; return NBDTers.contains(userName) ? "nbdt" : SUCCESS; } } Nov 20, 2008 Web Development with Apache Struts 2 14
  • 15. struts.xml <struts> <package name="/" extends="struts-default"> <action name="MyAction" class="myexample.MyAction"> <result name="input">/index.jsp</result> <result name="success">/good.jsp</result> <result name="nbdt">/nbdt.jsp</result> </action> </package> </struts> Nov 20, 2008 Web Development with Apache Struts 2 15
  • 16. A simple view JSP <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %> <html> <body> <h2>Welcome to JUG Lugano</h2> Hello, <s:property value="message" default="Guest" />, welcome to the first meeting of JUG Lugano! <s:form method="GET" action="MyAction.action"> Would you be so kind to tell me your name? <s:textfield name="userName" /> <s:submit value="Submit" /> </s:form> <s:actionerror/> <s:fielderror/> </body> </html> Nov 20, 2008 Web Development with Apache Struts 2 16
  • 17. Interceptors ● Used to implement “common” behaviours – Validations – Multiple submit filters – Logging ● Pre-defined interceptors Nov 20, 2008 Web Development with Apache Struts 2 17
  • 18. Formal validation ● Declarative, save tons of code <validators> <field name="userName"> <field-validator type="requiredstring"> <param name="trim">true</param> <message>Your name is required.</message> </field-validator> </field> </validators> Nov 20, 2008 Web Development with Apache Struts 2 18
  • 19. Interceptors ● Code that is invoked across Actions ● Many pre-defined interceptors – Parameter rename, cookie management, component behaviours (e.g. Checkboxes), background actions – Validation itself is an interceptor Nov 20, 2008 Web Development with Apache Struts 2 19
  • 20. Custom interceptors public interface Interceptor extends Serializable { public void destroy(); public void init(); public String intercept (ActionInvocation inv) throws Exception; } Nov 20, 2008 Web Development with Apache Struts 2 20
  • 21. Interceptors in struts.xml <struts> <package name="/" extends="struts-default"> <interceptors> <interceptor name="logger" class="..."/> </interceptors> <action name="MyAction" class="myexample.MyAction"> <interceptor-ref name="logger"/> <result name="success">/good.jsp</result> <result name="nbdt">/nbdt.jsp</result> <result name="input">/index.jsp</result> </action> </package> </struts> Nov 20, 2008 Web Development with Apache Struts 2 21
  • 22. Conclusion ● Robust, Struts 1 heritage ● Keeps up with the latest standards (POJOs, AOP, annotations, Spring, ...) ● “Conservative” approach, but easy ● Relevant sites: – struts.apache.org – beans.seartipy.com/2008/08/04/struts- 2-plugin-for-netbeans-ide- nbstruts2support/ Nov 20, 2008 Web Development with Apache Struts 2 22