SlideShare a Scribd company logo
1 of 119
Download to read offline
Jakarta Struts 1.1
      Ready for Prime Time



Atlanta Java Users Group (AJUG)
         August 20 2002
          Chuck Cavaness
Speaker Introductions
 Senior Technologist (S1 Corporation)
 Co-Author of Special Edition EJB 2.0
 Co-Author of Special Edition Java 2
 Technical Editor on Various J2EE Books including
 Special Edition JSP and Servlets, Special Edition
 J2EE, WebServices and WebLogic 7.0
 Articles for JavaWorld, InformIT, etc.
 Struts developer and user since the beginning
 Built several large J2EE Struts-based apps
 Author of Jakarta Struts from O’Reilly
Presentation Goals

 Introduce Struts from 5,280 ft
 Introduce the Struts 1.1 features
 Highlight the steps for developing a Struts
 application
 Subliminally emphasize the importance and
 benefit of using a framework like Struts
Presentation Goals (continued)
  No software to push
  No financial ties to the framework
  Purely Altruistic purpose




                   Buy my book!
What is Struts?
 An open source development framework for
 building web applications
 Based on Model-View-Controller (MVC)
 design paradigm
 Implementation of JSP Model 2 Architecture
 Created by Craig McClanahan and donated
 to Apache Software Foundation (ASF) in
 2000
 2nd release candidate of version 1.1 released
What is Struts? (continued)

 Consists of 8 Top-Level Packages
 Approx 250 Classes and Interfaces
Case Study

 Let’s create a dot com company
 Need a solid business model
 Something that many consumers are
 interested in
 Strong sells regardless of the economy
 or market
Beer 4 All (www.beer4all.com)
Beer4All Web Application
Beer4All Application (continued)
Purpose of Case Study

 A context for our Struts discussion
 We’ll use this case study off and on
 throughout the presentation
 Promote better beer drinking through
 technology
 And yes I do own www.Beer4All.com!
Selecting a UI Framework for Beer4All

 No framework
 (use straight JSP)
 Build our own framework
 Webwork
 Expresso
 Barracuda
 Cocoon
 SiteMesh
 Freemarker, Velocity and
 WebMacro
 XML/XSLT
 ???
                     Highly Paid Beer4All Architects Meet!
Why not use Struts?




Smart, but extremely underpaid developers who
 attended the AJUG Struts presentation ask…
Why consider Struts?
(Manager Version)
  Developed by Industry Experts
  Stable & Mature
  Manageable learning Curve
  Open Source
  1700 member User Community (50-100 new
  members each month)
  It’s probably similar to what you would build
  if not using Struts
  Good documentation – 5 books available
  soon!
Why consider Struts?
(Developer Version)


  Feature-rich        J2EE Technologies
  Free to develop &   Expert Developers
  deploy              and Committers
  Many supported      Large User
  third-party tools   Community
  Flexible &          Performant
  Extendable
Struts Framework Features
 Model 2 - MVC Implementation
 Internationalization(I18N) Support
 Rich JSP Tag Libraries
 Based on JSP, Servlet, XML, and Java
 Supports Java’s Write Once, Run Anywhere
 Philosophy
 Supports different model implementations
 (JavaBeans, EJB, etc.)
 Supports different presentation
 implementations( JSP, XML/XSLT, etc)
Struts Dependencies

 Java 1.2 or newer
 Servlet 2.2 and JSP 1.1 container
 XML parser compliant with JAXP 1.1 or
 newer (e.g. Xerces)
 Jakarta Commons packages
 JDBC 2.0 optional package
Decision: Let’s go with Struts!




     Beer4All Chief Architect proclaims!
Beer4All Logical Architecture
Let’s Talk about the Framework

 Controller
 Model
 View
 Configuration
 1.1 Features
The Controller Components
Controller Components

 ActionServlet – (Framework provided)
 RequestProcessor – (Framework provided)
 Action Classes – (You have to build these)
ActionServlet and RequestProcessor
    (What Do They Really Do?)

Receive the HttpServletRequest
Automatically populate a JavaBean
from the request parameters
Handle Locale and Content Type Issues
Determine which Action to invoke based
on URI
Provide extension points
ActionServlet Facts
 Extends javax.servlet.http.HttpServlet
 Receives all framework requests
 Selects proper application module
 Delegates request handling to the
 RequestProcessor instance
 One ActionServlet instance per web
 application
 Default implementation provided by
 framework (can extend if necessary)
 May go away in future versions
The RequestProcessor Class

 One instance per application module
 Processes all requests for module
 Invokes proper Action instance
 Default implementation provided by
 framework (can extend if necessary)
ActionServlet and RequestProcessor Diagram
What’s an Action Class?

 Extends org.apache.struts.action.Action
 Overrides the execute() method
 Acts as a bridge between user-invoked
 URI and a business method (Command
 pattern)
 Returns information about which view
 should be rendered next
 Part of the Controller, not the Model
Action Class Diagram
Action Sequence Diagram
     actionServlet          requestProccessor           loginAction              Beer4AllService

post/get

                     process()



                                           execute()



                                                                      authenticate()



                                                                           storeCredentials



                                      return ActionForward



                                                perform forward
Example Action execute() Method
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response )
throws Exception{
 String username = ((LoginForm)form).getUsername();
 String password = ((LoginForm)form).getPassword();
 // Obtain the service
 Beer4AllService serviceImpl = getBeer4AllService();


 // Authenticate the user
 UserView userView = serviceImpl.authenticate(username, password);


 // Store the user’s credentials
 UserContainer existingContainer = getUserContainer(request);
 existingContainer.setUserView( userView );


     // Return an ActionForward for the next page
     return mapping.findForward(Constants.SUCCESS_KEY);
 }
Beer4AllBaseAction Class
package com.cavaness.beer4all.framework;


import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import com.cavaness.beer4all.service.*;
import com.cavaness.beer4all.util.Constants;


abstract public class Beer4AllBaseAction extends Action {


    public Beer4AllService getBeer4AllService(){
        ServletContext ctx = getServlet().getServletContext();
        ServiceFactory factory =
         (ServiceFactory)ctx.getAttribute(Constants.SERVICE_FACTORY_KEY);
        return (Beer4AllService)factory.createService();
    }
}
Struts Includes Pre-built Action Classes

  ForwardAction
  DispatchAction
  LookupDispatchAction
  IncludeAction
  SwitchAction
The Model Components
Struts Model Components

 No built-in support for the model
 No model components provided
 Framework supports any component
 model (JavaBeans, EJB, Corba, JDO,
 etc.)
 Should always decouple the application
 from a specific model implementation.
Patterns De Jour
Model-View-Controller
Front Controller
Session Façade
Service Locator
Data Transfer Object (a.k.a ValueObject)
Command
Business Delegate
Factory
Data Access Object
Service to Worker
Business Delegate Pattern
Benefits of the Business Delegate Pattern

 Reduces coupling, increases
 manageability
 Hides complexity of remote services
 Exposes a simple uniform interface of
 the business tier to the client
 More complex features such as failure
 recovery are made easier
Beer4All Business Interface
package com.cavaness.beer4all.service;
import java.util.List;
import com.cavaness.beer4all.catalog.view.CatalogView;
import com.cavaness.beer4all.catalog.view.ItemView;
import com.cavaness.beer4all.common.view.UserView;
import com.cavaness.beer4all.common.exceptions.InvalidLoginException;
import com.cavaness.beer4all.common.exceptions.DatabaseException;


public interface Beer4AllService {
    public List getFeaturedItems() throws DatabaseException;
    public List getFeaturedCatalogs() throws DatabaseException;
    public ItemView getItemById( String itemId ) throws DatabaseException;
    public List getItemsInCatalog( String catalogId ) throws DatabaseException;
    public void logout(String email) throws DatabaseException;
    public UserView authenticate(String username, String password)
     throws DatabaseException, InvalidLoginException;
}
Beer4All Service Implementations
                            «interface»
                        Beer4AllService
                     +authenticate()
                     +getFeaturedCatalogs()
                     +getFeaturedItems()
                     +getItemById()
                     +getItemsInCatalog()
                     +logout()




Beer4AllEJBService    Beer4AllOJBService      Beer4AllDebugService
Beer4All Service Factory
framework              ServiceFactory                 Beer4AllOJBService   servletContext

            createService



                                        getServiceClass



                                        newInstance



                                                 setAttribute(service)
Struts with Enterprise JavaBeans


LoginAction          Business Delegate               SessionBean
              uses                       delegates
+execute()           +authenticate()             1   +authenticate()
The View Components
View Components
 JavaServer Pages
 HTML
 JavaScript and Stylesheets
 Multimedia Files
 Resource Bundles
 JavaBeans (Part of model used by views)
 JSP Custom Tags
 ActionForms
Struts JSP Tag Libraries

 HTML
 Bean
 Logic
 Nested
 Tiles
 Template
The HTML Tag Library

 Tags used to create Struts input forms
 Examples include (checkbox, image,
 link, submit, text, textarea)
HTML Tag Example
<table>
 <tr><b>Shipping Address</b></tr>
 <tr><td>Address:</td>
 <td><html:text name="checkoutForm" property="shippingAddress"/>
 </td></tr>
 <tr><td>City:</td>
 <td><html:text name="checkoutForm" property="shippingCity"/>
 </td></tr>
 <tr><td>State:</td>
 <td><html:text name="checkoutForm" property="shippingState"/>
 </td></tr>
 <tr><td>Postal:</td>
 <td><html:text name="checkoutForm" property="shippingPostal"/>
 </td></tr>
</table>
HTML Tag Example (continued)




              html:text
The Bean Tag Library

 Tags used for accessing JavaBeans
 and their properties
 Examples include (define, message,
 write)
Bean Tag Library Example
<b>
<bean:write name="UserContainer" property="cart.size“ scope="session"/>
</b>
<br>Current Total:
<b>
$<bean:write name="UserContainer" format="#,##0.00"
property="cart.totalPrice“ scope="session"/>
</b>
Bean Tag Example (continued)




        bean:message   bean:write
The Logic Tag Library

 Managing conditional generation of
 output text
 Looping over object collections for
 repetitive generation of output text
 Application flow management.
 Examples include (empty, lessThan,
 greaterThan, redirect, iterate)
Logic Tag Library Example
<logic:iterate id="cartItem" scope="session" name="UserContainer" property="cart.items">
 …
 <html:link
   page="/action/viewitemdetail?method=viewItem"
   paramName="cartItem"
   paramId="id"
   paramProperty="id">
   <bean:write name="cartItem" property="name"/>
 </html:link>
 …
</logic:iterate>
Logic Tag Library Example
(continued)




         logic:iterate
The Nested Tag Library

 Extend the base struts tags to allow
 them to relate to each other in a nested
 nature
 Created by Arron Bates
 Added to core beginning of 2002
Nested Tag Example
             UserView
           -firstName
           -lastName
           -dateOfBirth
           -email




              1     -profile

          UserProfileView
          -shippingAddress
          -billingAddress
          -creditCartInfo
Nested Tag Example (continued)
<html:form action="/some-action.do" >
 User View... <br>
 First: <html:text name=“user" property=“firstName" /><br>
 Last: <html:text name=“user" property=“lastName" /><br>
 DOB: <html:text name=“user" property=“dateOfBirth" /><br>
 <hr> User Profile... <br>
 Shipping Address: <html:text name=“user" property=“profile.shippingAddress" /><br>
 Billing Address: <html:text name=“user" property=“profile.billingAddress" /><br>
<hr> </html:form>
Nested Tag Example (continued)
<html:form action="/some-action.do" >
 User View... <br>
 First: <nested:text property=“firstName" /><br>
 Last: < nested :text property=“lastName" /><br>
 DOB: < nested :text property=“dateOfBirth" /><br>
  <nested:nest property=“profile">
   User Profile... <br>
   Shipping Address: <nested:text property=“shippingAddress" /><br>
   Billing Address: <nested:text property=“billingAddress" /><br>
  </nested:nest>
<hr> </html:form>
Nested Tag Benefits

 Tags can have a relationship
 Fewer attributes must be defined
 Can work against a single level
 Change is more manageable
What is an ActionForm?
 Java class that extends the
 org.apache.struts.action.ActionForm
 Captures user data from the Http
 request
 Stores the data temporarily
 Acts as a “firewall” between the
 presentation tier and the application
 Provides the ability to validate the user
 input
Beer4All LoginForm Example
public class LoginForm extends ActionForm {
 private String password = null;
 private String username = null;
 // … some code not shown
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
     ActionErrors errors = new ActionErrors();
     // Get access to the message resources for this application
     MessageResources resources =
         (MessageResources)request.getAttribute( Action.MESSAGES_KEY );
     if(getUsername() == null || getUsername().length() < 1) {
         String usernameLabel = resources.getMessage( "label.username" );
         errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.required", usernameLabel ));
     }
     if(getPassword() == null || getPassword().length() < 1) {
         String passwordLabel = resources.getMessage( "label.password" );
         errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.required", passwordLabel ));
     }
     return errors;
 }
ActionForm Sequence Diagram
ActionMessage and ActionError

 Used to signify general purpose
 informational and error messages
 Rely on the Resource Bundles
 JSP Tags can access them
ActionMessage Class Hierarchy
Beer4All Signin Error Messages

<tr class="RED">
 <td></td>
 <td>
   <html:messages id="error">
        <li><bean:write name="error"/></li>
   </html:messages>
 </td>
</tr>
Beer4All Signin Error Messages
(continued)


              html:messages
Putting it together
Configuring a Struts Application

 Create and edit the web app
 deployment descriptor (web.xml)
 Create and edit the struts-config.xml file
 Other configuration files might be
 necessary for Validator and tiles
Configuring web.xml for Struts

 Add servlet element
 Configure servlet-mapping element
 Add taglib elements
Beer4All web app Descriptor
<web-app>
<servlet>
 <servlet-name>beer4all</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>
<servlet-mapping>
 <servlet-name>beer4all</servlet-name>
 <url-pattern>/action/*</url-pattern>
</servlet-mapping>
<taglib>
 <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
 <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
… other tag library descriptors here
<</web-app>
Struts Configuration File

 Uses XML
 Defines the set of “rules” for a Struts
 application
 Starting with 1.1, can define multiple
 Gets parsed and loaded into memory at
 startup
Beer 4 All Struts Config File




  Let’s look at some source!
Internationalization Support

 Much of the framework’s functionality
 based on java.util.Locale
 Struts Uses Java Resource Bundles
Using Java Resource Bundles
global.title=Beer For All
label.featuredcatalogs=Featured Catalogs
label.featuredbeers=Featured Beers
label.username=Username
label.password=Password
errors.required={0} is required.
errors.minlength={0} can not be less than {1} characters.
errors.maxlength={0} can not be greater than {1} characters.
errors.invalid={0} is invalid.
errors.byte={0} must be an byte.
errors.short={0} must be an short.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.float={0} must be an float.
errors.double={0} must be an double.
errors.date={0} is not a date.
Locale-based Message Bundles
                                       Web Container


                          Web App
                         ClassLoader




                                         WEB-INF/classes

                                          Class Class
                                          Files Files
                                             Class
                                              Files

      Beer4AllMessageResources_en_US.properties




              Beer4AllMessageResources_de_DE.properties
Accessing messages from JSP Tags
 <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
 <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
 <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>


 <html:html locale="true">
 <html:form action="main">
 <head>
  <html:base/>
  <link rel="stylesheet" href="stylesheets/format_win_nav_main.css" type="text/css">
  <title><bean:message key="global.title"/></title>
 </head>
I18N is more than Resource Bundles

 Date and Time Formatting
 Currency Formatting
 Currency Conversion
 Text direction
 Proper Input Controllers
 Color Conventions
 etc…
Overview of Struts 1.1 Features
 Multi-Module Support     Validator integrated with
 Declarative Exception-   Core
 Handling                 Tiles integrated with
 Dynamic ActionForms      Core
 Nested Tag Library       PlugIns
 New Config Package       Uses Commons
 More Extension Points    Components
Multi-Module Support

 Separate, independent application
 modules (sub-applications)
 Supports parallel development
 Separate Struts configuration files
 Use the SwitchAction to move between
 application modules
Multi-Application Support
Exception Handling Capabilities

 Declarative or/and Programmatic
 Support
 Declarative added to 1.1
 Define which exceptions can be thrown
 for which actions
 Create your own custom
 ExceptionHandler, per action if
 necessary
How Declarative Exception Handling works
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response ) throws Exception {


 String username = ((LoginForm)form).getUsername();
 String password = ((LoginForm)form).getPassword();
 ServletContext context = getServlet().getServletContext();


     // Login through the security service
     Beer4AllService serviceImpl = this.getBeer4AllService();


     // Authenticate the user
     UserView userView = serviceImpl.authenticate(username, password);


     UserContainer existingContainer = getUserContainer(request);
     existingContainer.setUserView( userView );
     return mapping.findForward(Constants.SUCCESS_KEY);
 }
Declarative Exception Handling
Override the ExceptionHandler
      org.apache.struts.action.ExceptionHandler


      +execute()
      +storeException()




              CustomExceptionHandler


              +execute()
Programmatic Exception Handling
public ActionForward execute( ActionMapping mapping, ActionForm form,
HttpServletRequest request,
  HttpServletResponse response ) throws Exception{
      UserView userView = null;
      String username = ((LoginForm)form).getUsername();
      String password = ((LoginForm)form).getPassword();
      Beer4AllService serviceImpl = this.getBeer4AllService();
      try{
          // Attempt to authenticate the user
          userView = serviceImpl.authenticate(username, password);
      }catch( InvalidLoginException ex ){
          ActionErrors errors = new ActionErrors();
          ActionError newError = new ActionError( "" );
          errors.add( ActionErrors.GLOBAL_ERROR, newError );
          saveErrors( request errors);
          return mapping.findForward( Constants.FAILURE_KEY );
      }
      UserContainer existingContainer = getUserContainer(request);
      existingContainer.setUserView( userView );
      return mapping.findForward(Constants.SUCCESS_KEY);
  }
Programmatic or Declarative?

Use Declarative Exception Handling if
possible.
Customize the ExceptionHandler for
customized behavior
Use programmatic only when necessary
Dynamic ActionForms

 Define ActionForms declaratively
 Behave like regular ActionForms
 throughout the application
 No need to define ActionForm classes
DynaActionForm Example
 <form-bean

  name="checkoutForm"
  type="org.apache.struts.validator.DynaValidatorForm">
   <form-property name="shippingAddress" type="java.lang.String"/>
   <form-property name="shippingCity" type="java.lang.String"/>
   <form-property name="shippingState" type="java.lang.String"/>
   <form-property name="shippingPostal" type="java.lang.String"/>
 </form-bean>
DynaActionForm Example
(continued)
<table>
 <tr><b>Shipping Address</b></tr>
 <tr> <td>Address:</td>
  <td><html:text name="checkoutForm" property="shippingAddress"/></td></tr>
 <tr><td>City:</td>
 <td><html:text name="checkoutForm" property="shippingCity"/></td></tr>
 <tr><td>State:</td>
  <td><html:text name="checkoutForm" property="shippingState"/></td></tr>
 <tr><td>Postal:</td>
 <td><html:text name="checkoutForm" property="shippingPostal"/></td></tr>
</table>
The Struts Validator

 Open source Validation framework
 Developed by David Winterfeldt
 Integrated into Struts core during 1.1
 Extendable and Flexible
 Can be used outside of Struts
 Utilizes Regular Expressions
 Uses the Jakarta ORO Package
Validator Features

 Allows for regular expressions to be
 used
 Comes with many pre-built validation
 routines
 Supports Client-Side (JavaScript) and
 Server-Side (Java)
Adding Validator to a Struts
Application
 <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
  <set-property
   property="pathnames"
   value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
 </plug-in>
Validator configuration Files

 validator-rules.xml
 validation.xml
Validator-rules.xml File
<validator name="required"
      classname="org.apache.struts.util.StrutsValidator"
       method="validateRequired"
       methodParams="java.lang.Object,
             org.apache.commons.validator.ValidatorAction,
             org.apache.commons.validator.Field,
             org.apache.struts.action.ActionErrors,
             javax.servlet.http.HttpServletRequest"
          msg="errors.required">
//…some text deleted
Validator-rules.xml (continued)
<javascript><![CDATA[
 function validateRequired(form) {
   var bValid = true;
   var focusField = null;
   var i = 0;
   var fields = new Array();
   oRequired = new required();
   for (x in oRequired) {
   if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' ||
        form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' ||
        form[oRequired[x][0]].type == 'password') && (form[oRequired[x][0]].value == '')) {
        if (i == 0) { focusField = form[oRequired[x][0]]; }
            fields[i++] = oRequired[x][1];
            bValid = false;
        }
    }
</javascript>
Validator.xml File
<form name="checkoutForm">
<field
     property="shippingAddress"
     depends="required,mask">
     <arg0 key="label.address"/>
     <var>
      <var-name>mask</var-name>
      <var-value>^w+$</var-value>
     </var>
</field>
 …
Message Bundle
 …
 errors.required={0} is required.
 errors.minlength={0} can not be less than {1} characters.
 errors.maxlength={0} can not be greater than {1} characters.
 errors.invalid={0} is invalid.
 errors.byte={0} must be an byte.
 errors.short={0} must be an short.
 errors.integer={0} must be an integer.
 errors.long={0} must be an long.
 errors.float={0} must be an float.
 errors.double={0} must be an double.
 errors.date={0} is not a date.
 …
Validator Failures




               Validation failures
Struts Plug-in Capabilities

 Declarative means for “Startup Classes”
 Can declare multiple Plug-ins per sub-
 application
 Just need to implement the PlugIn
 interface
 Framework will call init() on startup and
 destroy() on shutdown
Using the Plug-in Functionality
Plug-in Example
<plug-in className="com.cavaness.beer4all.service.ServiceFactory">
  <set-property
    property="serviceClassName"
    value="com.cavaness.beer4all.service.Beer4AllOBJService"/>
</plug-in>
Beer4All ServiceFactory Plug-in
public class ServiceFactory implements PlugIn {
    private String serviceClassName = null;
    public String getServiceClassName(){
        return serviceClassName;
    }
    public void setServiceClassName( String className ){
        this.serviceClassName = className;
    }
public void init(ActionServlet servlet, ApplicationConfig config){
        // Perform initialization functionality here
    }
    public void destroy(){
        // Perform shutdown functionality here
    }
}
Tiles Library Features
 Advanced templating mechanism
 Set of JSP Tags
 Supports the idea of Layouts (known as Tiles)
 Layouts based on Locale/Channel
 Tiles can be reused
 Created by Cedric Dumoulin (while working at
 S1 coincidently )
 Added to core in Struts 1.1
Beer4All Layout
              Header Region/Tile


            Menu Bar Region/Tile




           Body Content Region/Tile




            Copyright Region/Tile
Beer4All Layout Tile
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles"%>


<html:html>
<head><title><bean:message key="global.title"/></title> </head>
<body topmargin="0" leftmargin="0" bgcolor="#FFFFFF">
 <tiles:insert attribute="header" />
 <tiles:insert attribute=“banner"/>
 <tiles:insert attribute="body-content"/>
 <tiles:insert attribute="copyright"/>
</body>
</html:html>
Beer4All JSPs Using Tiles
<%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %>


<tiles:insert page="/layouts/beer4AllDefaultLayout.jsp" flush="true">
  <tiles:put name="header" value="/common/header.jsp" />
  <tiles:put name=“banner" value="/common/banner.jsp" />
  <tiles:put name="body-content" value="/main.jsp" />
  <tiles:put name="copyright" value="/common/copyright.jsp" />
</tiles:insert>


<%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %>


<tiles:insert page="/layouts/beer4AllDefaultLayout.jsp" flush="true">
 <tiles:put name="header" value="/common/header.jsp" />
 <tiles:put name=“banner" value="/common/banner.jsp" />
 <tiles:put name="body-content" value="/beer.jsp" />
 <tiles:put name="copyright" value="/common/copyright.jsp" />
</tiles:insert>
Tiles XML Definition
<!DOCTYPE tiles-definitions PUBLIC “-//Apache Software Foundation//DTD Tiles
Configuration//EN" “http://jakarta.apache.org/struts/dtds/tiles-config.dtd">


<tiles-definitions>
<definition name=“beer4All.default" path="/layouts/beer4allDefaultLayout.jsp">
 <put name="header" value="/common/header.jsp" />
 <put name=“banner" value="/common/banner.jsp" />
 <put name="copyright" value="/common/copyright.jsp" />
</definition>
</tiles-definitions>
Extending Tiles Definitions

<tiles-definitions>
<definition name=“beer4All.custom" extends=”beer4All.default”>
 <put name="copyright" value="/common/new-copyright.jsp" />
</definition>
</tiles-definitions>
Other Tiles Resources

 Cedric’s Site
 (http://www.lifl.fr/~dumoulin/tiles/)
 My Chapter on Tiles
 (http://www.theserverside.com/resources/strutsreview.jsp)
Jakarta Commons Packages
 BeanUtils
 Collections
 Digester
 DBCP
 Logging
 Lang
 Resources
Logging in a Struts Application

 Struts utilizes Commons Logging
 (jakarta.apache.org/Commons)
 Various logging implementations
 supported (JDK1.4, log4J, Console,
 etc.)
Logging Example

Log logger = LogFactory.getLog( getClass() );
logger.debug( "LoginAction entered" );
try{
  // Attempt to authenticate the user
  userView = serviceImpl.authenticate(username, password);
}catch( InvalidLoginException ex ){
  logger.error( "Exception in the LoginAction class", ex );
  //…
Packaging and Deployment

 Package as a Web ARchive File (WAR)
 Deploys into any Servlet 2.2, JSP 1.1
 compliant web container
 You can also leave it exploded
 Use Ant to build and deploy
Beer4All Directory Structure
Beer4All Is a Success!
Beer Drinkers Everywhere Rejoice




    The world unites by using Beer4All.com
Resources
 Jakarta Struts Home Site
 (jakarta.apache.org/struts)
 Ted Husted’s Site (http://www.husted.com/struts)
 TheServerSide Struts Book Review
 (http://www.theserverside.com/resources/strutsreview.jsp)
 Jakarta Struts from O’Reilly
 (Available for order on Amazon right now!)
 Struts user and dev mailing lists
 Atlanta Struts user group
 (http://www.open-tools.org/struts-atlanta/index.jsp)
Third-Party Tools for Struts

 Struts Console
 (http://www.jamesholmes.com/struts)

 Easy Struts Project
 (http://easystruts.sourceforge.net)

 Adalon (http://www.synthis.com)
 More
 (jakarta.apache.org/struts/resources)
When is 1.1 GA?


   I Don’t Know!
Q&A

 What did I miss?

More Related Content

What's hot

Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSFSoftServe
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2Jim Driscoll
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depthVinay Kumar
 
vCloud SDK for PHP - Introduction
vCloud SDK for PHP - IntroductionvCloud SDK for PHP - Introduction
vCloud SDK for PHP - IntroductionPablo Roesch
 
Mike Taulty OData (NxtGen User Group UK)
Mike Taulty OData (NxtGen User Group UK)Mike Taulty OData (NxtGen User Group UK)
Mike Taulty OData (NxtGen User Group UK)ukdpe
 
Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Sunil kumar Mohanty
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsGuy Nir
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Courseguest764934
 
JSF basics
JSF basicsJSF basics
JSF basicsairbo
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009kensipe
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring Sunil kumar Mohanty
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
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 frameworksSunil Patil
 

What's hot (20)

Spring Core
Spring CoreSpring Core
Spring Core
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
 
Jsf
JsfJsf
Jsf
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Spring framework in depth
Spring framework in depthSpring framework in depth
Spring framework in depth
 
vCloud SDK for PHP - Introduction
vCloud SDK for PHP - IntroductionvCloud SDK for PHP - Introduction
vCloud SDK for PHP - Introduction
 
Mike Taulty OData (NxtGen User Group UK)
Mike Taulty OData (NxtGen User Group UK)Mike Taulty OData (NxtGen User Group UK)
Mike Taulty OData (NxtGen User Group UK)
 
Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample Spring IOC advantages and developing spring application sample
Spring IOC advantages and developing spring application sample
 
Maven
MavenMaven
Maven
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
 
Struts Introduction Course
Struts Introduction CourseStruts Introduction Course
Struts Introduction Course
 
JSF basics
JSF basicsJSF basics
JSF basics
 
Spring 3 MVC CodeMash 2009
Spring 3 MVC   CodeMash 2009Spring 3 MVC   CodeMash 2009
Spring 3 MVC CodeMash 2009
 
Introduction to jsf 2
Introduction to jsf 2Introduction to jsf 2
Introduction to jsf 2
 
Different Types of Containers in Spring
Different Types of Containers in Spring Different Types of Containers in Spring
Different Types of Containers in Spring
 
Spring 4 Web App
Spring 4 Web AppSpring 4 Web App
Spring 4 Web App
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
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
 
Spring aop
Spring aopSpring aop
Spring aop
 

Viewers also liked

Viewers also liked (8)

javainheritance
javainheritancejavainheritance
javainheritance
 
AWTEventModel
AWTEventModelAWTEventModel
AWTEventModel
 
Presosutra
PresosutraPresosutra
Presosutra
 
2015 ii - listado de cursos dac - áreas junio 30 (1)
2015 ii - listado de cursos dac - áreas junio 30 (1)2015 ii - listado de cursos dac - áreas junio 30 (1)
2015 ii - listado de cursos dac - áreas junio 30 (1)
 
javaarray
javaarrayjavaarray
javaarray
 
Jan Lok Pal
Jan Lok PalJan Lok Pal
Jan Lok Pal
 
javanetworking
javanetworkingjavanetworking
javanetworking
 
javaexceptions
javaexceptionsjavaexceptions
javaexceptions
 

Similar to struts

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 FrameworksSunil Patil
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session ManagementFahad Golra
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play FrameworkKnoldus Inc.
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit frameworkSunil Kumar
 
Was 5.1 To 6.1
Was 5.1 To 6.1Was 5.1 To 6.1
Was 5.1 To 6.1tsmanyam
 
Was 5.1 To 6.1 Updated
Was 5.1 To 6.1 UpdatedWas 5.1 To 6.1 Updated
Was 5.1 To 6.1 Updatedtsmanyam
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-frameworkWBUTTUTORIALS
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Red Hat Developers
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Play framework : A Walkthrough
Play framework : A WalkthroughPlay framework : A Walkthrough
Play framework : A Walkthroughmitesh_sharma
 
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 womenlissa cidhi
 
ASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperEmad Alashi
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCSunpawet Somsin
 

Similar to struts (20)

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
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
 
Intoduction to Play Framework
Intoduction to Play FrameworkIntoduction to Play Framework
Intoduction to Play Framework
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit framework
 
Was 5.1 To 6.1
Was 5.1 To 6.1Was 5.1 To 6.1
Was 5.1 To 6.1
 
Was 5.1 To 6.1 Updated
Was 5.1 To 6.1 UpdatedWas 5.1 To 6.1 Updated
Was 5.1 To 6.1 Updated
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-framework
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
Boost Development With Java EE7 On EAP7 (Demitris Andreadis)
 
Mvc3 crash
Mvc3 crashMvc3 crash
Mvc3 crash
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Tu1 1 5l
Tu1 1 5lTu1 1 5l
Tu1 1 5l
 
Play framework : A Walkthrough
Play framework : A WalkthroughPlay framework : A Walkthrough
Play framework : A Walkthrough
 
Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)
 
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
 
Struts
StrutsStruts
Struts
 
ASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperASP.NET MVC One Step Deeper
ASP.NET MVC One Step Deeper
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

More from Arjun Shanka (20)

Asp.net w3schools
Asp.net w3schoolsAsp.net w3schools
Asp.net w3schools
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Sms several papers
Sms several papersSms several papers
Sms several papers
 
Jun 2012(1)
Jun 2012(1)Jun 2012(1)
Jun 2012(1)
 
System simulation 06_cs82
System simulation 06_cs82System simulation 06_cs82
System simulation 06_cs82
 
javarmi
javarmijavarmi
javarmi
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
hibernate
hibernatehibernate
hibernate
 
javapackage
javapackagejavapackage
javapackage
 
swingbasics
swingbasicsswingbasics
swingbasics
 
spring-tutorial
spring-tutorialspring-tutorial
spring-tutorial
 
javathreads
javathreadsjavathreads
javathreads
 
javabeans
javabeansjavabeans
javabeans
 
72185-26528-StrutsMVC
72185-26528-StrutsMVC72185-26528-StrutsMVC
72185-26528-StrutsMVC
 
javaiostream
javaiostreamjavaiostream
javaiostream
 
servlets
servletsservlets
servlets
 
slides6
slides6slides6
slides6
 
06-Event-Handlingadvansed
06-Event-Handlingadvansed06-Event-Handlingadvansed
06-Event-Handlingadvansed
 
Java_Comb
Java_CombJava_Comb
Java_Comb
 
Java-Events
Java-EventsJava-Events
Java-Events
 

Recently uploaded

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

struts

  • 1. Jakarta Struts 1.1 Ready for Prime Time Atlanta Java Users Group (AJUG) August 20 2002 Chuck Cavaness
  • 2. Speaker Introductions Senior Technologist (S1 Corporation) Co-Author of Special Edition EJB 2.0 Co-Author of Special Edition Java 2 Technical Editor on Various J2EE Books including Special Edition JSP and Servlets, Special Edition J2EE, WebServices and WebLogic 7.0 Articles for JavaWorld, InformIT, etc. Struts developer and user since the beginning Built several large J2EE Struts-based apps Author of Jakarta Struts from O’Reilly
  • 3. Presentation Goals Introduce Struts from 5,280 ft Introduce the Struts 1.1 features Highlight the steps for developing a Struts application Subliminally emphasize the importance and benefit of using a framework like Struts
  • 4. Presentation Goals (continued) No software to push No financial ties to the framework Purely Altruistic purpose Buy my book!
  • 5. What is Struts? An open source development framework for building web applications Based on Model-View-Controller (MVC) design paradigm Implementation of JSP Model 2 Architecture Created by Craig McClanahan and donated to Apache Software Foundation (ASF) in 2000 2nd release candidate of version 1.1 released
  • 6. What is Struts? (continued) Consists of 8 Top-Level Packages Approx 250 Classes and Interfaces
  • 7. Case Study Let’s create a dot com company Need a solid business model Something that many consumers are interested in Strong sells regardless of the economy or market
  • 8. Beer 4 All (www.beer4all.com)
  • 11. Purpose of Case Study A context for our Struts discussion We’ll use this case study off and on throughout the presentation Promote better beer drinking through technology And yes I do own www.Beer4All.com!
  • 12. Selecting a UI Framework for Beer4All No framework (use straight JSP) Build our own framework Webwork Expresso Barracuda Cocoon SiteMesh Freemarker, Velocity and WebMacro XML/XSLT ??? Highly Paid Beer4All Architects Meet!
  • 13. Why not use Struts? Smart, but extremely underpaid developers who attended the AJUG Struts presentation ask…
  • 14. Why consider Struts? (Manager Version) Developed by Industry Experts Stable & Mature Manageable learning Curve Open Source 1700 member User Community (50-100 new members each month) It’s probably similar to what you would build if not using Struts Good documentation – 5 books available soon!
  • 15. Why consider Struts? (Developer Version) Feature-rich J2EE Technologies Free to develop & Expert Developers deploy and Committers Many supported Large User third-party tools Community Flexible & Performant Extendable
  • 16. Struts Framework Features Model 2 - MVC Implementation Internationalization(I18N) Support Rich JSP Tag Libraries Based on JSP, Servlet, XML, and Java Supports Java’s Write Once, Run Anywhere Philosophy Supports different model implementations (JavaBeans, EJB, etc.) Supports different presentation implementations( JSP, XML/XSLT, etc)
  • 17. Struts Dependencies Java 1.2 or newer Servlet 2.2 and JSP 1.1 container XML parser compliant with JAXP 1.1 or newer (e.g. Xerces) Jakarta Commons packages JDBC 2.0 optional package
  • 18. Decision: Let’s go with Struts! Beer4All Chief Architect proclaims!
  • 20. Let’s Talk about the Framework Controller Model View Configuration 1.1 Features
  • 22. Controller Components ActionServlet – (Framework provided) RequestProcessor – (Framework provided) Action Classes – (You have to build these)
  • 23. ActionServlet and RequestProcessor (What Do They Really Do?) Receive the HttpServletRequest Automatically populate a JavaBean from the request parameters Handle Locale and Content Type Issues Determine which Action to invoke based on URI Provide extension points
  • 24. ActionServlet Facts Extends javax.servlet.http.HttpServlet Receives all framework requests Selects proper application module Delegates request handling to the RequestProcessor instance One ActionServlet instance per web application Default implementation provided by framework (can extend if necessary) May go away in future versions
  • 25. The RequestProcessor Class One instance per application module Processes all requests for module Invokes proper Action instance Default implementation provided by framework (can extend if necessary)
  • 27. What’s an Action Class? Extends org.apache.struts.action.Action Overrides the execute() method Acts as a bridge between user-invoked URI and a business method (Command pattern) Returns information about which view should be rendered next Part of the Controller, not the Model
  • 29. Action Sequence Diagram actionServlet requestProccessor loginAction Beer4AllService post/get process() execute() authenticate() storeCredentials return ActionForward perform forward
  • 30. Example Action execute() Method public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception{ String username = ((LoginForm)form).getUsername(); String password = ((LoginForm)form).getPassword(); // Obtain the service Beer4AllService serviceImpl = getBeer4AllService(); // Authenticate the user UserView userView = serviceImpl.authenticate(username, password); // Store the user’s credentials UserContainer existingContainer = getUserContainer(request); existingContainer.setUserView( userView ); // Return an ActionForward for the next page return mapping.findForward(Constants.SUCCESS_KEY); }
  • 31. Beer4AllBaseAction Class package com.cavaness.beer4all.framework; import org.apache.struts.action.*; import javax.servlet.http.*; import javax.servlet.ServletContext; import com.cavaness.beer4all.service.*; import com.cavaness.beer4all.util.Constants; abstract public class Beer4AllBaseAction extends Action { public Beer4AllService getBeer4AllService(){ ServletContext ctx = getServlet().getServletContext(); ServiceFactory factory = (ServiceFactory)ctx.getAttribute(Constants.SERVICE_FACTORY_KEY); return (Beer4AllService)factory.createService(); } }
  • 32. Struts Includes Pre-built Action Classes ForwardAction DispatchAction LookupDispatchAction IncludeAction SwitchAction
  • 34. Struts Model Components No built-in support for the model No model components provided Framework supports any component model (JavaBeans, EJB, Corba, JDO, etc.) Should always decouple the application from a specific model implementation.
  • 35. Patterns De Jour Model-View-Controller Front Controller Session Façade Service Locator Data Transfer Object (a.k.a ValueObject) Command Business Delegate Factory Data Access Object Service to Worker
  • 37. Benefits of the Business Delegate Pattern Reduces coupling, increases manageability Hides complexity of remote services Exposes a simple uniform interface of the business tier to the client More complex features such as failure recovery are made easier
  • 38. Beer4All Business Interface package com.cavaness.beer4all.service; import java.util.List; import com.cavaness.beer4all.catalog.view.CatalogView; import com.cavaness.beer4all.catalog.view.ItemView; import com.cavaness.beer4all.common.view.UserView; import com.cavaness.beer4all.common.exceptions.InvalidLoginException; import com.cavaness.beer4all.common.exceptions.DatabaseException; public interface Beer4AllService { public List getFeaturedItems() throws DatabaseException; public List getFeaturedCatalogs() throws DatabaseException; public ItemView getItemById( String itemId ) throws DatabaseException; public List getItemsInCatalog( String catalogId ) throws DatabaseException; public void logout(String email) throws DatabaseException; public UserView authenticate(String username, String password) throws DatabaseException, InvalidLoginException; }
  • 39. Beer4All Service Implementations «interface» Beer4AllService +authenticate() +getFeaturedCatalogs() +getFeaturedItems() +getItemById() +getItemsInCatalog() +logout() Beer4AllEJBService Beer4AllOJBService Beer4AllDebugService
  • 40. Beer4All Service Factory framework ServiceFactory Beer4AllOJBService servletContext createService getServiceClass newInstance setAttribute(service)
  • 41. Struts with Enterprise JavaBeans LoginAction Business Delegate SessionBean uses delegates +execute() +authenticate() 1 +authenticate()
  • 43. View Components JavaServer Pages HTML JavaScript and Stylesheets Multimedia Files Resource Bundles JavaBeans (Part of model used by views) JSP Custom Tags ActionForms
  • 44. Struts JSP Tag Libraries HTML Bean Logic Nested Tiles Template
  • 45. The HTML Tag Library Tags used to create Struts input forms Examples include (checkbox, image, link, submit, text, textarea)
  • 46. HTML Tag Example <table> <tr><b>Shipping Address</b></tr> <tr><td>Address:</td> <td><html:text name="checkoutForm" property="shippingAddress"/> </td></tr> <tr><td>City:</td> <td><html:text name="checkoutForm" property="shippingCity"/> </td></tr> <tr><td>State:</td> <td><html:text name="checkoutForm" property="shippingState"/> </td></tr> <tr><td>Postal:</td> <td><html:text name="checkoutForm" property="shippingPostal"/> </td></tr> </table>
  • 47. HTML Tag Example (continued) html:text
  • 48. The Bean Tag Library Tags used for accessing JavaBeans and their properties Examples include (define, message, write)
  • 49. Bean Tag Library Example <b> <bean:write name="UserContainer" property="cart.size“ scope="session"/> </b> <br>Current Total: <b> $<bean:write name="UserContainer" format="#,##0.00" property="cart.totalPrice“ scope="session"/> </b>
  • 50. Bean Tag Example (continued) bean:message bean:write
  • 51. The Logic Tag Library Managing conditional generation of output text Looping over object collections for repetitive generation of output text Application flow management. Examples include (empty, lessThan, greaterThan, redirect, iterate)
  • 52. Logic Tag Library Example <logic:iterate id="cartItem" scope="session" name="UserContainer" property="cart.items"> … <html:link page="/action/viewitemdetail?method=viewItem" paramName="cartItem" paramId="id" paramProperty="id"> <bean:write name="cartItem" property="name"/> </html:link> … </logic:iterate>
  • 53. Logic Tag Library Example (continued) logic:iterate
  • 54. The Nested Tag Library Extend the base struts tags to allow them to relate to each other in a nested nature Created by Arron Bates Added to core beginning of 2002
  • 55. Nested Tag Example UserView -firstName -lastName -dateOfBirth -email 1 -profile UserProfileView -shippingAddress -billingAddress -creditCartInfo
  • 56. Nested Tag Example (continued) <html:form action="/some-action.do" > User View... <br> First: <html:text name=“user" property=“firstName" /><br> Last: <html:text name=“user" property=“lastName" /><br> DOB: <html:text name=“user" property=“dateOfBirth" /><br> <hr> User Profile... <br> Shipping Address: <html:text name=“user" property=“profile.shippingAddress" /><br> Billing Address: <html:text name=“user" property=“profile.billingAddress" /><br> <hr> </html:form>
  • 57. Nested Tag Example (continued) <html:form action="/some-action.do" > User View... <br> First: <nested:text property=“firstName" /><br> Last: < nested :text property=“lastName" /><br> DOB: < nested :text property=“dateOfBirth" /><br> <nested:nest property=“profile"> User Profile... <br> Shipping Address: <nested:text property=“shippingAddress" /><br> Billing Address: <nested:text property=“billingAddress" /><br> </nested:nest> <hr> </html:form>
  • 58. Nested Tag Benefits Tags can have a relationship Fewer attributes must be defined Can work against a single level Change is more manageable
  • 59. What is an ActionForm? Java class that extends the org.apache.struts.action.ActionForm Captures user data from the Http request Stores the data temporarily Acts as a “firewall” between the presentation tier and the application Provides the ability to validate the user input
  • 60. Beer4All LoginForm Example public class LoginForm extends ActionForm { private String password = null; private String username = null; // … some code not shown public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); // Get access to the message resources for this application MessageResources resources = (MessageResources)request.getAttribute( Action.MESSAGES_KEY ); if(getUsername() == null || getUsername().length() < 1) { String usernameLabel = resources.getMessage( "label.username" ); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.required", usernameLabel )); } if(getPassword() == null || getPassword().length() < 1) { String passwordLabel = resources.getMessage( "label.password" ); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("errors.required", passwordLabel )); } return errors; }
  • 62. ActionMessage and ActionError Used to signify general purpose informational and error messages Rely on the Resource Bundles JSP Tags can access them
  • 64. Beer4All Signin Error Messages <tr class="RED"> <td></td> <td> <html:messages id="error"> <li><bean:write name="error"/></li> </html:messages> </td> </tr>
  • 65. Beer4All Signin Error Messages (continued) html:messages
  • 67. Configuring a Struts Application Create and edit the web app deployment descriptor (web.xml) Create and edit the struts-config.xml file Other configuration files might be necessary for Validator and tiles
  • 68. Configuring web.xml for Struts Add servlet element Configure servlet-mapping element Add taglib elements
  • 69. Beer4All web app Descriptor <web-app> <servlet> <servlet-name>beer4all</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> <servlet-mapping> <servlet-name>beer4all</servlet-name> <url-pattern>/action/*</url-pattern> </servlet-mapping> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> … other tag library descriptors here <</web-app>
  • 70. Struts Configuration File Uses XML Defines the set of “rules” for a Struts application Starting with 1.1, can define multiple Gets parsed and loaded into memory at startup
  • 71. Beer 4 All Struts Config File Let’s look at some source!
  • 72. Internationalization Support Much of the framework’s functionality based on java.util.Locale Struts Uses Java Resource Bundles
  • 73. Using Java Resource Bundles global.title=Beer For All label.featuredcatalogs=Featured Catalogs label.featuredbeers=Featured Beers label.username=Username label.password=Password errors.required={0} is required. errors.minlength={0} can not be less than {1} characters. errors.maxlength={0} can not be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be an byte. errors.short={0} must be an short. errors.integer={0} must be an integer. errors.long={0} must be an long. errors.float={0} must be an float. errors.double={0} must be an double. errors.date={0} is not a date.
  • 74. Locale-based Message Bundles Web Container Web App ClassLoader WEB-INF/classes Class Class Files Files Class Files Beer4AllMessageResources_en_US.properties Beer4AllMessageResources_de_DE.properties
  • 75. Accessing messages from JSP Tags <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <html:html locale="true"> <html:form action="main"> <head> <html:base/> <link rel="stylesheet" href="stylesheets/format_win_nav_main.css" type="text/css"> <title><bean:message key="global.title"/></title> </head>
  • 76. I18N is more than Resource Bundles Date and Time Formatting Currency Formatting Currency Conversion Text direction Proper Input Controllers Color Conventions etc…
  • 77. Overview of Struts 1.1 Features Multi-Module Support Validator integrated with Declarative Exception- Core Handling Tiles integrated with Dynamic ActionForms Core Nested Tag Library PlugIns New Config Package Uses Commons More Extension Points Components
  • 78. Multi-Module Support Separate, independent application modules (sub-applications) Supports parallel development Separate Struts configuration files Use the SwitchAction to move between application modules
  • 80. Exception Handling Capabilities Declarative or/and Programmatic Support Declarative added to 1.1 Define which exceptions can be thrown for which actions Create your own custom ExceptionHandler, per action if necessary
  • 81. How Declarative Exception Handling works public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception { String username = ((LoginForm)form).getUsername(); String password = ((LoginForm)form).getPassword(); ServletContext context = getServlet().getServletContext(); // Login through the security service Beer4AllService serviceImpl = this.getBeer4AllService(); // Authenticate the user UserView userView = serviceImpl.authenticate(username, password); UserContainer existingContainer = getUserContainer(request); existingContainer.setUserView( userView ); return mapping.findForward(Constants.SUCCESS_KEY); }
  • 83. Override the ExceptionHandler org.apache.struts.action.ExceptionHandler +execute() +storeException() CustomExceptionHandler +execute()
  • 84. Programmatic Exception Handling public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception{ UserView userView = null; String username = ((LoginForm)form).getUsername(); String password = ((LoginForm)form).getPassword(); Beer4AllService serviceImpl = this.getBeer4AllService(); try{ // Attempt to authenticate the user userView = serviceImpl.authenticate(username, password); }catch( InvalidLoginException ex ){ ActionErrors errors = new ActionErrors(); ActionError newError = new ActionError( "" ); errors.add( ActionErrors.GLOBAL_ERROR, newError ); saveErrors( request errors); return mapping.findForward( Constants.FAILURE_KEY ); } UserContainer existingContainer = getUserContainer(request); existingContainer.setUserView( userView ); return mapping.findForward(Constants.SUCCESS_KEY); }
  • 85. Programmatic or Declarative? Use Declarative Exception Handling if possible. Customize the ExceptionHandler for customized behavior Use programmatic only when necessary
  • 86. Dynamic ActionForms Define ActionForms declaratively Behave like regular ActionForms throughout the application No need to define ActionForm classes
  • 87. DynaActionForm Example <form-bean name="checkoutForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="shippingAddress" type="java.lang.String"/> <form-property name="shippingCity" type="java.lang.String"/> <form-property name="shippingState" type="java.lang.String"/> <form-property name="shippingPostal" type="java.lang.String"/> </form-bean>
  • 88. DynaActionForm Example (continued) <table> <tr><b>Shipping Address</b></tr> <tr> <td>Address:</td> <td><html:text name="checkoutForm" property="shippingAddress"/></td></tr> <tr><td>City:</td> <td><html:text name="checkoutForm" property="shippingCity"/></td></tr> <tr><td>State:</td> <td><html:text name="checkoutForm" property="shippingState"/></td></tr> <tr><td>Postal:</td> <td><html:text name="checkoutForm" property="shippingPostal"/></td></tr> </table>
  • 89. The Struts Validator Open source Validation framework Developed by David Winterfeldt Integrated into Struts core during 1.1 Extendable and Flexible Can be used outside of Struts Utilizes Regular Expressions Uses the Jakarta ORO Package
  • 90. Validator Features Allows for regular expressions to be used Comes with many pre-built validation routines Supports Client-Side (JavaScript) and Server-Side (Java)
  • 91. Adding Validator to a Struts Application <plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/> </plug-in>
  • 92. Validator configuration Files validator-rules.xml validation.xml
  • 93. Validator-rules.xml File <validator name="required" classname="org.apache.struts.util.StrutsValidator" method="validateRequired" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" msg="errors.required"> //…some text deleted
  • 94. Validator-rules.xml (continued) <javascript><![CDATA[ function validateRequired(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oRequired = new required(); for (x in oRequired) { if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' || form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' || form[oRequired[x][0]].type == 'password') && (form[oRequired[x][0]].value == '')) { if (i == 0) { focusField = form[oRequired[x][0]]; } fields[i++] = oRequired[x][1]; bValid = false; } } </javascript>
  • 95. Validator.xml File <form name="checkoutForm"> <field property="shippingAddress" depends="required,mask"> <arg0 key="label.address"/> <var> <var-name>mask</var-name> <var-value>^w+$</var-value> </var> </field> …
  • 96. Message Bundle … errors.required={0} is required. errors.minlength={0} can not be less than {1} characters. errors.maxlength={0} can not be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be an byte. errors.short={0} must be an short. errors.integer={0} must be an integer. errors.long={0} must be an long. errors.float={0} must be an float. errors.double={0} must be an double. errors.date={0} is not a date. …
  • 97. Validator Failures Validation failures
  • 98. Struts Plug-in Capabilities Declarative means for “Startup Classes” Can declare multiple Plug-ins per sub- application Just need to implement the PlugIn interface Framework will call init() on startup and destroy() on shutdown
  • 99. Using the Plug-in Functionality
  • 100. Plug-in Example <plug-in className="com.cavaness.beer4all.service.ServiceFactory"> <set-property property="serviceClassName" value="com.cavaness.beer4all.service.Beer4AllOBJService"/> </plug-in>
  • 101. Beer4All ServiceFactory Plug-in public class ServiceFactory implements PlugIn { private String serviceClassName = null; public String getServiceClassName(){ return serviceClassName; } public void setServiceClassName( String className ){ this.serviceClassName = className; } public void init(ActionServlet servlet, ApplicationConfig config){ // Perform initialization functionality here } public void destroy(){ // Perform shutdown functionality here } }
  • 102. Tiles Library Features Advanced templating mechanism Set of JSP Tags Supports the idea of Layouts (known as Tiles) Layouts based on Locale/Channel Tiles can be reused Created by Cedric Dumoulin (while working at S1 coincidently ) Added to core in Struts 1.1
  • 103. Beer4All Layout Header Region/Tile Menu Bar Region/Tile Body Content Region/Tile Copyright Region/Tile
  • 104. Beer4All Layout Tile <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles"%> <html:html> <head><title><bean:message key="global.title"/></title> </head> <body topmargin="0" leftmargin="0" bgcolor="#FFFFFF"> <tiles:insert attribute="header" /> <tiles:insert attribute=“banner"/> <tiles:insert attribute="body-content"/> <tiles:insert attribute="copyright"/> </body> </html:html>
  • 105. Beer4All JSPs Using Tiles <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %> <tiles:insert page="/layouts/beer4AllDefaultLayout.jsp" flush="true"> <tiles:put name="header" value="/common/header.jsp" /> <tiles:put name=“banner" value="/common/banner.jsp" /> <tiles:put name="body-content" value="/main.jsp" /> <tiles:put name="copyright" value="/common/copyright.jsp" /> </tiles:insert> <%@ taglib uri="/WEB-INF/tiles.tld" prefix="tiles" %> <tiles:insert page="/layouts/beer4AllDefaultLayout.jsp" flush="true"> <tiles:put name="header" value="/common/header.jsp" /> <tiles:put name=“banner" value="/common/banner.jsp" /> <tiles:put name="body-content" value="/beer.jsp" /> <tiles:put name="copyright" value="/common/copyright.jsp" /> </tiles:insert>
  • 106. Tiles XML Definition <!DOCTYPE tiles-definitions PUBLIC “-//Apache Software Foundation//DTD Tiles Configuration//EN" “http://jakarta.apache.org/struts/dtds/tiles-config.dtd"> <tiles-definitions> <definition name=“beer4All.default" path="/layouts/beer4allDefaultLayout.jsp"> <put name="header" value="/common/header.jsp" /> <put name=“banner" value="/common/banner.jsp" /> <put name="copyright" value="/common/copyright.jsp" /> </definition> </tiles-definitions>
  • 107. Extending Tiles Definitions <tiles-definitions> <definition name=“beer4All.custom" extends=”beer4All.default”> <put name="copyright" value="/common/new-copyright.jsp" /> </definition> </tiles-definitions>
  • 108. Other Tiles Resources Cedric’s Site (http://www.lifl.fr/~dumoulin/tiles/) My Chapter on Tiles (http://www.theserverside.com/resources/strutsreview.jsp)
  • 109. Jakarta Commons Packages BeanUtils Collections Digester DBCP Logging Lang Resources
  • 110. Logging in a Struts Application Struts utilizes Commons Logging (jakarta.apache.org/Commons) Various logging implementations supported (JDK1.4, log4J, Console, etc.)
  • 111. Logging Example Log logger = LogFactory.getLog( getClass() ); logger.debug( "LoginAction entered" ); try{ // Attempt to authenticate the user userView = serviceImpl.authenticate(username, password); }catch( InvalidLoginException ex ){ logger.error( "Exception in the LoginAction class", ex ); //…
  • 112. Packaging and Deployment Package as a Web ARchive File (WAR) Deploys into any Servlet 2.2, JSP 1.1 compliant web container You can also leave it exploded Use Ant to build and deploy
  • 114. Beer4All Is a Success!
  • 115. Beer Drinkers Everywhere Rejoice The world unites by using Beer4All.com
  • 116. Resources Jakarta Struts Home Site (jakarta.apache.org/struts) Ted Husted’s Site (http://www.husted.com/struts) TheServerSide Struts Book Review (http://www.theserverside.com/resources/strutsreview.jsp) Jakarta Struts from O’Reilly (Available for order on Amazon right now!) Struts user and dev mailing lists Atlanta Struts user group (http://www.open-tools.org/struts-atlanta/index.jsp)
  • 117. Third-Party Tools for Struts Struts Console (http://www.jamesholmes.com/struts) Easy Struts Project (http://easystruts.sourceforge.net) Adalon (http://www.synthis.com) More (jakarta.apache.org/struts/resources)
  • 118. When is 1.1 GA? I Don’t Know!
  • 119. Q&A What did I miss?