SlideShare a Scribd company logo
1 of 43
Download to read offline
11/05/2003




              Step by Step Guide
             for building a simple
              Struts Application


                                     1
11/05/2003




                 Sang Shin
                 sang.shin@sun.com
                www.javapassion.com
             Java ™ Technology Evangelist
               Sun Microsystems, Inc.
                                            2
11/05/2003




         Disclaimer & Acknowledgments
     ?       Even though Sang Shin is a full-time employees of Sun
             Microsystems, the contents here are created as their own personal
             endeavor and thus does not reflect any official stance of Sun
             Microsystems.
     ?       Sun Microsystems is not responsible for any inaccuracies in the
             contents.
     ?       Acknowledgments:
              –   The source code examples are from Keld Hansen




                                                                                 3
11/05/2003




      Revision History
      ?      11/10/2003: version 1: created by Sang Shin
      ?      Things to do
              – Speaker notes need to be added
              – Contents still need to be polished




                                                           4
11/05/2003




             Sample App We are
               going to build



                                 5
11/05/2003




             Sample App
             ?   Keld Hansen's submit application
             ?   The source files and Ant build.xml file
                 can be found in the hands-on/homework
                 material in our class website
                  –   Creating ActionForm object
                  –   Creating Action object
                  –   Forwarding at either success or failure
                  –   Input validation
                  –   Internationalizaition


                                                                6
11/05/2003




             Steps to follow



                               7
11/05/2003




             Steps
             1. Create development directory structure
             2. Write web.xml
             3. Write struts-config.xml
             4. Write ActionForm classes
             5. Write Action classes
             6. Create ApplicationResource.properties
             7. Write JSP pages
             8. Write ant build script
             9. Build, deploy, and test the application
                                                          8
11/05/2003




             Step 1: Create Development
                 Directory Structure


                                          9
11/05/2003




             Source Directory Structure
             ?   Same directory structure for any typical
                 Web application
                 –   W e will use the source directory structure of Java
                     W SDP Web applications
             ?   Ant build script should be written
                 accordingly




                                                                           10
11/05/2003




             Dev.
             Directory
             Structure




                         11
11/05/2003




             Struts
             *.jar files




                           12
11/05/2003




             Step 2: Write web.xml
             Deployment Descriptor


                                     13
11/05/2003




             web.xml
             ?   Same structure as any other Web
                 application
                 –   Servlet definition and mapping of ActionServlet
             ?   There are servral Struts specific
                 <init-param> elements
             ?   Struts tag libraries also need to be defined




                                                                       14
11/05/2003




             Example: web.xml
         1 <!DOCTYPE web-app
         2  PUBLIC quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//ENquot;
         3  quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtdquot;>
         4
         5 <web-app>
         6  <display-name>Advanced J2EE Programming Class Sample App</display-name>
         7
         8  <!-- Standard Action Servlet Configuration (with debugging) -->
         9  <servlet>
         10    <servlet-name>action</servlet-name>
         11    <servlet-class>
         12       org.apache.struts.action.ActionServlet
         13    </servlet-class>
         14    <init-param>
         15      <param-name>application</param-name>
         16      <param-value>ApplicationResources</param-value>
         17    </init-param>
         18    <init-param>
         19      <param-name>config</param-name>
         20      <param-value>/WEB-INF/struts-config.xml</param-value>
         21    </init-param>
         22 </servlet>                                                              15
11/05/2003




             Example: web.xml
         1    <!-- Standard Action Servlet Mapping -->
         2    <servlet-mapping>
         3     <servlet-name>action</servlet-name>
         4     <url-pattern>*.do</url-pattern>
         5    </servlet-mapping>
         6
         7    <!-- Struts Tag Library Descriptors -->
         8    <taglib>
         9     <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
         10      <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
         11    </taglib>
         12    <taglib>
         13      <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
         14      <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
         15    </taglib>
         16    <taglib>
         17      <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
         18      <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
         19    </taglib>
         20
         21   </web-app>
         22                                                                     16
11/05/2003




               Step 3: Write
             struts-config.xml


                                 17
11/05/2003




             Struts-config.xml
             ?   Identify required input forms and then
                 define them as <form-bean> elements
             ?   Identify required Action's and then define
                 them as <action> elements within <action-
                 mappings> element
                 –   make sure same value of name attribute of <form-
                     bean> is used as the value of name attribute of
                     <action> element
                 –   define if you want input validation
             ?   Decide view selection logic and specify
                 them as <forward> element within
                                                                        18
                 <action> element
11/05/2003




    struts-config.xml: ActionMapping
      1      <?xml version=quot;1.0quot; encoding=quot;ISO-8859-1quot; ?>
      2
      3 <!DOCTYPE struts-config PUBLIC
      4       quot;-//Apache Software Foundation//DTD Struts Configuration 1.1//ENquot;
      5       quot;http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtdquot;>
      6
      7 <struts-config>
      8
      9 <!-- ========== Form Bean Definitions ================= -->
      10  <form-beans>
      11
      12    <form-bean name=quot;submitFormquot;
      13                  type=quot;hansen.playground.SubmitFormquot;/>
      14
      15  </form-beans>


                                                                             19
11/05/2003




    struts-config.xml: ActionMapping
             1
             2    <!-- ========== Action Mapping Definitions ============ -->
             3     <action-mappings>
             4
             5     <action path=quot;/submitquot;
             6              type=quot;hansen.playground.SubmitActionquot;
             7              name=quot;submitFormquot;
             8              input=quot;/submit.jspquot;
             9             scope=quot;requestquot;
             10             validate=quot;truequot;>
             11     <forward name=quot;successquot; path=quot;/submit.jspquot;/>
             12     <forward name=quot;failurequot; path=quot;/submit.jspquot;/>
             13     </action>
             14
             15    </action-mappings>
             16
             17   </struts-config>
                                                                                20
11/05/2003




                Step 4: Write
             ActionForm classes


                                  21
11/05/2003




             ActionForm Class
             ?   Extend org.apache.struts.action.ActionForm
                 class
             ?   Decide set of properties that reflect the
                 input form
             ?   Write getter and setter methods for each
                 property
             ?   Write validate() mtehod if input validation is
                 desired


                                                                  22
11/05/2003




             Model: ActionForm
             1    package hansen.playground;
             2
             3    import javax.servlet.http.HttpServletRequest;
             4    import org.apache.struts.action.*;
             5
             6    public final class SubmitForm extends ActionForm {
             7
             8      /* Last Name */
             9      private String lastName = quot;Hansenquot;; // default value
             10     public String getLastName() {
             11       return (this.lastName);
             12     }
             13     public void setLastName(String lastName) {
             14       this.lastName = lastName;
             15     }
             16
             17      /* Address */
             18      private String address = null;
             19      public String getAddress() {
             20        return (this.address);
             21      }
             22      public void setAddress(String address) {
             23        this.address = address;
             24      }
             25    ...
                                                                           23
11/05/2003




             Model: ActionForm
             1    public final class SubmitForm extends ActionForm {
             2
             3    ...
             4      public ActionErrors validate(ActionMapping mapping,
             5          HttpServletRequest request) {
             6
             7          ...
             8
             9           // Check for mandatory data
             10           ActionErrors errors = new ActionErrors();
             11           if (lastName == null || lastName.equals(quot;quot;)) {
             12             errors.add(quot;Last Namequot;, new ActionError(quot;error.lastNamequot;));
             13           }
             14           if (address == null || address.equals(quot;quot;)) {
             15             errors.add(quot;Addressquot;, new ActionError(quot;error.addressquot;));
             16           }
             17           if (sex == null || sex.equals(quot;quot;)) {
             18             errors.add(quot;Sexquot;, new ActionError(quot;error.sexquot;));
             19           }
             20           if (age == null || age.equals(quot;quot;)) {
             21             errors.add(quot;Agequot;, new ActionError(quot;error.agequot;));
             22           }
             23           return errors;
             24         }
             25    ..
             26    }                                                                      24
11/05/2003




             Step 5: Write
             Action classes


                              25
11/05/2003




             Action Classes
             ?   Extend org.apache.struts.action.Action
                 class
             ?   Handle the request
                 –   Decide what kind of server-side objects (EJB, JDO,
                     etc.) can be invoked
             ?   Based on the outcome, select the next view




                                                                          26
11/05/2003




     Example: Action Class
      1 package hansen.playground;
      2
      3 import javax.servlet.http.*;
      4 import org.apache.struts.action.*;
      5
      6 public final class SubmitAction extends Action {
      7
      8    public ActionForward execute(ActionMapping mapping,
      9                                 ActionForm form,
      10                                HttpServletRequest request,
      11                                HttpServletResponse response) {
      12
      13      SubmitForm f = (SubmitForm) form; // get the form bean
      14      // and take the last name value
      15      String lastName = f.getLastName();
      16      // Translate the name to upper case
      17      //and save it in the request object
      18      request.setAttribute(quot;lastNamequot;, lastName.toUpperCase());
      19
      20      // Forward control to the specified success target
      21      return (mapping.findForward(quot;successquot;));
      22    }
      23 }
                                                                          27
11/05/2003




                     Step 6: Create
             ApplicationResource.properties



                                              28
11/05/2003




             Resource file
             ?   Create resource file for default locale
             ?   Create resource files for other locales




                                                           29
11/05/2003




             Example:
             ApplicationResource.properties
             1   errors.header=<h4>Validation Error(s)</h4><ul>
             2   errors.footer=</ul><hr>
             3
             4   error.lastName=<li>Enter your last name
             5   error.address=<li>Enter your address
             6   error.sex=<li>Enter your sex
             7   error.age=<li>Enter your age




                                                                  30
11/05/2003




             Step 7: Write JSP pages


                                       31
11/05/2003




             JSP Pages
             ?   Write one JSP page for each view
             ?   Use Struts tags for
                 –   Handing HTML input forms
                 –   Writing out messages




                                                    32
11/05/2003



        Example: submit.jsp
         1    <%@ page language=quot;javaquot; %>
         2    <%@ taglib uri=quot;/WEB-INF/struts-bean.tldquot; prefix=quot;beanquot; %>
         3    <%@ taglib uri=quot;/WEB-INF/struts-html.tldquot; prefix=quot;htmlquot; %>
         4    <%@ taglib uri=quot;/WEB-INF/struts-logic.tldquot; prefix=quot;logicquot; %>
         5
         6    <html>
         7    <head><title>Submit example</title></head>
         8    <body>
         9
         10    <h3>Example Submit Page</h3>
         11
         12    <html:errors/>
         13
         14    <html:form action=quot;submit.doquot;>
         15    Last Name: <html:text property=quot;lastNamequot;/><br>
         16    Address: <html:textarea property=quot;addressquot;/><br>
         17    Sex:    <html:radio property=quot;sexquot; value=quot;Mquot;/>Male
         18           <html:radio property=quot;sexquot; value=quot;Fquot;/>Female<br>
         19    Married: <html:checkbox property=quot;marriedquot;/><br>
         20    Age:     <html:select property=quot;agequot;>
         21            <html:option value=quot;aquot;>0-19</html:option>
         22            <html:option value=quot;bquot;>20-49</html:option>
         23            <html:option value=quot;cquot;>50-</html:option>
         24           </html:select><br>
         25           <html:submit/>
         26    </html:form>                                                  33
11/05/2003


        Example: submit.jsp
        1    <logic:present name=quot;lastNamequot; scope=quot;requestquot;>
        2    Hello
        3    <logic:equal name=quot;submitFormquot; property=quot;agequot; value=quot;aquot;>
        4     young
        5    </logic:equal>
        6    <logic:equal name=quot;submitFormquot; property=quot;agequot; value=quot;cquot;>
        7     old
        8    </logic:equal>
        9    <bean:write name=quot;lastNamequot; scope=quot;requestquot;/>
        10    </logic:present>
        11
        12    </body>
        13    </html>




                                                                        34
11/05/2003




             Step 8: Write Ant Build
                     Script


                                       35
11/05/2003




             After
             ant build




                         36
11/05/2003




             Step 9: Build, Deploy,
             and Test Application


                                      37
11/05/2003




             Accessing Web Application




                                         38
11/05/2003




             Accessing Web Application




                                         39
11/05/2003




             Accessing Web Application




                                         40
11/05/2003




             Accessing Web Application




                                         41
11/05/2003




             Accessing Web Application




                                         42
11/05/2003




             Live your life
             with Passion!

                              43

More Related Content

What's hot

Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
elliando dias
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-Hibernate
Jay Shah
 

What's hot (20)

Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
Introduction to Struts 1.3
Introduction to Struts 1.3Introduction to Struts 1.3
Introduction to Struts 1.3
 
Struts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web ApplicationsStruts An Open-source Architecture for Web Applications
Struts An Open-source Architecture for Web Applications
 
Struts introduction
Struts introductionStruts introduction
Struts introduction
 
Struts course material
Struts course materialStruts course material
Struts course material
 
Struts(mrsurwar) ppt
Struts(mrsurwar) pptStruts(mrsurwar) ppt
Struts(mrsurwar) ppt
 
Struts2
Struts2Struts2
Struts2
 
Struts,Jsp,Servlet
Struts,Jsp,ServletStruts,Jsp,Servlet
Struts,Jsp,Servlet
 
Struts2
Struts2Struts2
Struts2
 
Struts2
Struts2Struts2
Struts2
 
Struts
StrutsStruts
Struts
 
Strut2-Spring-Hibernate
Strut2-Spring-HibernateStrut2-Spring-Hibernate
Strut2-Spring-Hibernate
 
Struts2 notes
Struts2 notesStruts2 notes
Struts2 notes
 
Struts & spring framework issues
Struts & spring framework issuesStruts & spring framework issues
Struts & spring framework issues
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
 
Skillwise Struts.x
Skillwise Struts.xSkillwise Struts.x
Skillwise Struts.x
 
SpringMVC
SpringMVCSpringMVC
SpringMVC
 
Spring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVCSpring - Part 4 - Spring MVC
Spring - Part 4 - Spring MVC
 
Spring Web MVC
Spring Web MVCSpring Web MVC
Spring Web MVC
 

Viewers also liked

Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
guest764934
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
Syed Shahul
 

Viewers also liked (10)

Manual Basico De Struts
Manual Basico De StrutsManual Basico De Struts
Manual Basico De Struts
 
Introduction to Struts 2
Introduction to Struts 2Introduction to Struts 2
Introduction to Struts 2
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 
Frameworks in java
Frameworks in javaFrameworks in java
Frameworks in java
 
Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts Build Java Web Application Using Apache Struts
Build Java Web Application Using Apache Struts
 
Liferay 6 and vaadin portlets
Liferay 6 and vaadin portletsLiferay 6 and vaadin portlets
Liferay 6 and vaadin portlets
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
 
Java & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate FrameworkJava & J2EE Struts with Hibernate Framework
Java & J2EE Struts with Hibernate Framework
 
Liferay Developer Best Practices for a Successful Deployment
Liferay Developer Best Practices for a Successful DeploymentLiferay Developer Best Practices for a Successful Deployment
Liferay Developer Best Practices for a Successful Deployment
 

Similar to Step by Step Guide for building a simple Struts Application

Step By Step Guide For Buidling Simple Struts App Speakernoted
Step By Step Guide For Buidling Simple Struts App SpeakernotedStep By Step Guide For Buidling Simple Struts App Speakernoted
Step By Step Guide For Buidling Simple Struts App Speakernoted
Harjinder Singh
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
Sagar Nakul
 
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Rati Manandhar
 
Maven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patterns
elliando dias
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
Carles Farré
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Mats Bryntse
 

Similar to Step by Step Guide for building a simple Struts Application (20)

Optaros Surf Code Camp Walkthrough 2
Optaros Surf Code Camp Walkthrough 2Optaros Surf Code Camp Walkthrough 2
Optaros Surf Code Camp Walkthrough 2
 
Step By Step Guide For Buidling Simple Struts App Speakernoted
Step By Step Guide For Buidling Simple Struts App SpeakernotedStep By Step Guide For Buidling Simple Struts App Speakernoted
Step By Step Guide For Buidling Simple Struts App Speakernoted
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Strutsjspservlet
Strutsjspservlet Strutsjspservlet
Strutsjspservlet
 
Optaros Surf Code Camp Walkthrough 1
Optaros Surf Code Camp Walkthrough 1Optaros Surf Code Camp Walkthrough 1
Optaros Surf Code Camp Walkthrough 1
 
Optaros Surf Code Camp Lab 4
Optaros Surf Code Camp Lab 4Optaros Surf Code Camp Lab 4
Optaros Surf Code Camp Lab 4
 
JSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph PicklJSUG - Spring by Christoph Pickl
JSUG - Spring by Christoph Pickl
 
Spring Surf 101
Spring Surf 101Spring Surf 101
Spring Surf 101
 
Ibm
IbmIbm
Ibm
 
Creating Yahoo Mobile Widgets
Creating Yahoo Mobile WidgetsCreating Yahoo Mobile Widgets
Creating Yahoo Mobile Widgets
 
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
Stepbystepguideforbuidlingsimplestrutsapp 090702025438-phpapp02
 
Servlet30 20081218
Servlet30 20081218Servlet30 20081218
Servlet30 20081218
 
T5 Oli Aro
T5 Oli AroT5 Oli Aro
T5 Oli Aro
 
Real-World AJAX with ASP.NET
Real-World AJAX with ASP.NETReal-World AJAX with ASP.NET
Real-World AJAX with ASP.NET
 
Maven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patternsMaven 2.0 - Improve your build patterns
Maven 2.0 - Improve your build patterns
 
Spring and DWR
Spring and DWRSpring and DWR
Spring and DWR
 
Optaros Surf Code Camp Lab 2
Optaros Surf Code Camp Lab 2Optaros Surf Code Camp Lab 2
Optaros Surf Code Camp Lab 2
 
Java Server Faces 1.2 presented (2007)
Java Server Faces 1.2 presented (2007)Java Server Faces 1.2 presented (2007)
Java Server Faces 1.2 presented (2007)
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (3/3)
 
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NETSilicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
Silicon Valley CodeCamp 2008: High performance Ajax with ExtJS and ASP.NET
 

More from elliando dias

Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
elliando dias
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
elliando dias
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
elliando dias
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
elliando dias
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
elliando dias
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
elliando dias
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
elliando dias
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
elliando dias
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
elliando dias
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
elliando dias
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
elliando dias
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
elliando dias
 

More from elliando dias (20)

Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Why you should be excited about ClojureScript
Why you should be excited about ClojureScriptWhy you should be excited about ClojureScript
Why you should be excited about ClojureScript
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Nomenclatura e peças de container
Nomenclatura  e peças de containerNomenclatura  e peças de container
Nomenclatura e peças de container
 
Geometria Projetiva
Geometria ProjetivaGeometria Projetiva
Geometria Projetiva
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
Javascript Libraries
Javascript LibrariesJavascript Libraries
Javascript Libraries
 
How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!How to Make an Eight Bit Computer and Save the World!
How to Make an Eight Bit Computer and Save the World!
 
Ragel talk
Ragel talkRagel talk
Ragel talk
 
A Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the WebA Practical Guide to Connecting Hardware to the Web
A Practical Guide to Connecting Hardware to the Web
 
Introdução ao Arduino
Introdução ao ArduinoIntrodução ao Arduino
Introdução ao Arduino
 
Minicurso arduino
Minicurso arduinoMinicurso arduino
Minicurso arduino
 
Incanter Data Sorcery
Incanter Data SorceryIncanter Data Sorcery
Incanter Data Sorcery
 
Rango
RangoRango
Rango
 
Fab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine DesignFab.in.a.box - Fab Academy: Machine Design
Fab.in.a.box - Fab Academy: Machine Design
 
The Digital Revolution: Machines that makes
The Digital Revolution: Machines that makesThe Digital Revolution: Machines that makes
The Digital Revolution: Machines that makes
 
Hadoop + Clojure
Hadoop + ClojureHadoop + Clojure
Hadoop + Clojure
 
Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.Hadoop - Simple. Scalable.
Hadoop - Simple. Scalable.
 
Hadoop and Hive Development at Facebook
Hadoop and Hive Development at FacebookHadoop and Hive Development at Facebook
Hadoop and Hive Development at Facebook
 
Multi-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case StudyMulti-core Parallelization in Clojure - a Case Study
Multi-core Parallelization in Clojure - a Case Study
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Step by Step Guide for building a simple Struts Application

  • 1. 11/05/2003 Step by Step Guide for building a simple Struts Application 1
  • 2. 11/05/2003 Sang Shin sang.shin@sun.com www.javapassion.com Java ™ Technology Evangelist Sun Microsystems, Inc. 2
  • 3. 11/05/2003 Disclaimer & Acknowledgments ? Even though Sang Shin is a full-time employees of Sun Microsystems, the contents here are created as their own personal endeavor and thus does not reflect any official stance of Sun Microsystems. ? Sun Microsystems is not responsible for any inaccuracies in the contents. ? Acknowledgments: – The source code examples are from Keld Hansen 3
  • 4. 11/05/2003 Revision History ? 11/10/2003: version 1: created by Sang Shin ? Things to do – Speaker notes need to be added – Contents still need to be polished 4
  • 5. 11/05/2003 Sample App We are going to build 5
  • 6. 11/05/2003 Sample App ? Keld Hansen's submit application ? The source files and Ant build.xml file can be found in the hands-on/homework material in our class website – Creating ActionForm object – Creating Action object – Forwarding at either success or failure – Input validation – Internationalizaition 6
  • 7. 11/05/2003 Steps to follow 7
  • 8. 11/05/2003 Steps 1. Create development directory structure 2. Write web.xml 3. Write struts-config.xml 4. Write ActionForm classes 5. Write Action classes 6. Create ApplicationResource.properties 7. Write JSP pages 8. Write ant build script 9. Build, deploy, and test the application 8
  • 9. 11/05/2003 Step 1: Create Development Directory Structure 9
  • 10. 11/05/2003 Source Directory Structure ? Same directory structure for any typical Web application – W e will use the source directory structure of Java W SDP Web applications ? Ant build script should be written accordingly 10
  • 11. 11/05/2003 Dev. Directory Structure 11
  • 12. 11/05/2003 Struts *.jar files 12
  • 13. 11/05/2003 Step 2: Write web.xml Deployment Descriptor 13
  • 14. 11/05/2003 web.xml ? Same structure as any other Web application – Servlet definition and mapping of ActionServlet ? There are servral Struts specific <init-param> elements ? Struts tag libraries also need to be defined 14
  • 15. 11/05/2003 Example: web.xml 1 <!DOCTYPE web-app 2 PUBLIC quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//ENquot; 3 quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtdquot;> 4 5 <web-app> 6 <display-name>Advanced J2EE Programming Class Sample App</display-name> 7 8 <!-- Standard Action Servlet Configuration (with debugging) --> 9 <servlet> 10 <servlet-name>action</servlet-name> 11 <servlet-class> 12 org.apache.struts.action.ActionServlet 13 </servlet-class> 14 <init-param> 15 <param-name>application</param-name> 16 <param-value>ApplicationResources</param-value> 17 </init-param> 18 <init-param> 19 <param-name>config</param-name> 20 <param-value>/WEB-INF/struts-config.xml</param-value> 21 </init-param> 22 </servlet> 15
  • 16. 11/05/2003 Example: web.xml 1 <!-- Standard Action Servlet Mapping --> 2 <servlet-mapping> 3 <servlet-name>action</servlet-name> 4 <url-pattern>*.do</url-pattern> 5 </servlet-mapping> 6 7 <!-- Struts Tag Library Descriptors --> 8 <taglib> 9 <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> 10 <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> 11 </taglib> 12 <taglib> 13 <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> 14 <taglib-location>/WEB-INF/struts-html.tld</taglib-location> 15 </taglib> 16 <taglib> 17 <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> 18 <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> 19 </taglib> 20 21 </web-app> 22 16
  • 17. 11/05/2003 Step 3: Write struts-config.xml 17
  • 18. 11/05/2003 Struts-config.xml ? Identify required input forms and then define them as <form-bean> elements ? Identify required Action's and then define them as <action> elements within <action- mappings> element – make sure same value of name attribute of <form- bean> is used as the value of name attribute of <action> element – define if you want input validation ? Decide view selection logic and specify them as <forward> element within 18 <action> element
  • 19. 11/05/2003 struts-config.xml: ActionMapping 1 <?xml version=quot;1.0quot; encoding=quot;ISO-8859-1quot; ?> 2 3 <!DOCTYPE struts-config PUBLIC 4 quot;-//Apache Software Foundation//DTD Struts Configuration 1.1//ENquot; 5 quot;http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtdquot;> 6 7 <struts-config> 8 9 <!-- ========== Form Bean Definitions ================= --> 10 <form-beans> 11 12 <form-bean name=quot;submitFormquot; 13 type=quot;hansen.playground.SubmitFormquot;/> 14 15 </form-beans> 19
  • 20. 11/05/2003 struts-config.xml: ActionMapping 1 2 <!-- ========== Action Mapping Definitions ============ --> 3 <action-mappings> 4 5 <action path=quot;/submitquot; 6 type=quot;hansen.playground.SubmitActionquot; 7 name=quot;submitFormquot; 8 input=quot;/submit.jspquot; 9 scope=quot;requestquot; 10 validate=quot;truequot;> 11 <forward name=quot;successquot; path=quot;/submit.jspquot;/> 12 <forward name=quot;failurequot; path=quot;/submit.jspquot;/> 13 </action> 14 15 </action-mappings> 16 17 </struts-config> 20
  • 21. 11/05/2003 Step 4: Write ActionForm classes 21
  • 22. 11/05/2003 ActionForm Class ? Extend org.apache.struts.action.ActionForm class ? Decide set of properties that reflect the input form ? Write getter and setter methods for each property ? Write validate() mtehod if input validation is desired 22
  • 23. 11/05/2003 Model: ActionForm 1 package hansen.playground; 2 3 import javax.servlet.http.HttpServletRequest; 4 import org.apache.struts.action.*; 5 6 public final class SubmitForm extends ActionForm { 7 8 /* Last Name */ 9 private String lastName = quot;Hansenquot;; // default value 10 public String getLastName() { 11 return (this.lastName); 12 } 13 public void setLastName(String lastName) { 14 this.lastName = lastName; 15 } 16 17 /* Address */ 18 private String address = null; 19 public String getAddress() { 20 return (this.address); 21 } 22 public void setAddress(String address) { 23 this.address = address; 24 } 25 ... 23
  • 24. 11/05/2003 Model: ActionForm 1 public final class SubmitForm extends ActionForm { 2 3 ... 4 public ActionErrors validate(ActionMapping mapping, 5 HttpServletRequest request) { 6 7 ... 8 9 // Check for mandatory data 10 ActionErrors errors = new ActionErrors(); 11 if (lastName == null || lastName.equals(quot;quot;)) { 12 errors.add(quot;Last Namequot;, new ActionError(quot;error.lastNamequot;)); 13 } 14 if (address == null || address.equals(quot;quot;)) { 15 errors.add(quot;Addressquot;, new ActionError(quot;error.addressquot;)); 16 } 17 if (sex == null || sex.equals(quot;quot;)) { 18 errors.add(quot;Sexquot;, new ActionError(quot;error.sexquot;)); 19 } 20 if (age == null || age.equals(quot;quot;)) { 21 errors.add(quot;Agequot;, new ActionError(quot;error.agequot;)); 22 } 23 return errors; 24 } 25 .. 26 } 24
  • 25. 11/05/2003 Step 5: Write Action classes 25
  • 26. 11/05/2003 Action Classes ? Extend org.apache.struts.action.Action class ? Handle the request – Decide what kind of server-side objects (EJB, JDO, etc.) can be invoked ? Based on the outcome, select the next view 26
  • 27. 11/05/2003 Example: Action Class 1 package hansen.playground; 2 3 import javax.servlet.http.*; 4 import org.apache.struts.action.*; 5 6 public final class SubmitAction extends Action { 7 8 public ActionForward execute(ActionMapping mapping, 9 ActionForm form, 10 HttpServletRequest request, 11 HttpServletResponse response) { 12 13 SubmitForm f = (SubmitForm) form; // get the form bean 14 // and take the last name value 15 String lastName = f.getLastName(); 16 // Translate the name to upper case 17 //and save it in the request object 18 request.setAttribute(quot;lastNamequot;, lastName.toUpperCase()); 19 20 // Forward control to the specified success target 21 return (mapping.findForward(quot;successquot;)); 22 } 23 } 27
  • 28. 11/05/2003 Step 6: Create ApplicationResource.properties 28
  • 29. 11/05/2003 Resource file ? Create resource file for default locale ? Create resource files for other locales 29
  • 30. 11/05/2003 Example: ApplicationResource.properties 1 errors.header=<h4>Validation Error(s)</h4><ul> 2 errors.footer=</ul><hr> 3 4 error.lastName=<li>Enter your last name 5 error.address=<li>Enter your address 6 error.sex=<li>Enter your sex 7 error.age=<li>Enter your age 30
  • 31. 11/05/2003 Step 7: Write JSP pages 31
  • 32. 11/05/2003 JSP Pages ? Write one JSP page for each view ? Use Struts tags for – Handing HTML input forms – Writing out messages 32
  • 33. 11/05/2003 Example: submit.jsp 1 <%@ page language=quot;javaquot; %> 2 <%@ taglib uri=quot;/WEB-INF/struts-bean.tldquot; prefix=quot;beanquot; %> 3 <%@ taglib uri=quot;/WEB-INF/struts-html.tldquot; prefix=quot;htmlquot; %> 4 <%@ taglib uri=quot;/WEB-INF/struts-logic.tldquot; prefix=quot;logicquot; %> 5 6 <html> 7 <head><title>Submit example</title></head> 8 <body> 9 10 <h3>Example Submit Page</h3> 11 12 <html:errors/> 13 14 <html:form action=quot;submit.doquot;> 15 Last Name: <html:text property=quot;lastNamequot;/><br> 16 Address: <html:textarea property=quot;addressquot;/><br> 17 Sex: <html:radio property=quot;sexquot; value=quot;Mquot;/>Male 18 <html:radio property=quot;sexquot; value=quot;Fquot;/>Female<br> 19 Married: <html:checkbox property=quot;marriedquot;/><br> 20 Age: <html:select property=quot;agequot;> 21 <html:option value=quot;aquot;>0-19</html:option> 22 <html:option value=quot;bquot;>20-49</html:option> 23 <html:option value=quot;cquot;>50-</html:option> 24 </html:select><br> 25 <html:submit/> 26 </html:form> 33
  • 34. 11/05/2003 Example: submit.jsp 1 <logic:present name=quot;lastNamequot; scope=quot;requestquot;> 2 Hello 3 <logic:equal name=quot;submitFormquot; property=quot;agequot; value=quot;aquot;> 4 young 5 </logic:equal> 6 <logic:equal name=quot;submitFormquot; property=quot;agequot; value=quot;cquot;> 7 old 8 </logic:equal> 9 <bean:write name=quot;lastNamequot; scope=quot;requestquot;/> 10 </logic:present> 11 12 </body> 13 </html> 34
  • 35. 11/05/2003 Step 8: Write Ant Build Script 35
  • 36. 11/05/2003 After ant build 36
  • 37. 11/05/2003 Step 9: Build, Deploy, and Test Application 37
  • 38. 11/05/2003 Accessing Web Application 38
  • 39. 11/05/2003 Accessing Web Application 39
  • 40. 11/05/2003 Accessing Web Application 40
  • 41. 11/05/2003 Accessing Web Application 41
  • 42. 11/05/2003 Accessing Web Application 42
  • 43. 11/05/2003 Live your life with Passion! 43