helloopensource

 

hellowaffle

Page history last edited by paulo 2 yrs ago

 Hello Waffle

This Tutorial will show you how to create and deploy a simple java web application using Waffle,  Eclipse Web Tools Platform (WTP) and Tomcat Web Server.

 

Main Learning's

  • After following this tutorial you will learn how to:
  • Download and install Waffle
  • Create a simple Java web project using Waffle
  • Run a Waffle sample Web application  on the Tomcat server within WTP
  • Create a WAR file and deploy it on Tomcat
  • Run the Waffle sample Web application  in Tomcat

 

Versions used:

  • OS: Windows XP V1.6
  • JDK version 1.5.0_12
  • Apache Tomcat v 5.5.23
  • WTP - Web Tools Platform All-In-One Packages - R2.0  (from June 26, 2007)
  • Waffle 1.0-beta-1 (28 July 2007)

 

Assumptions:

 

Common Issue:

  • Incorrect Tomcat installation directory on WTP  

 

Tutorial Steps:

  1. Go to the Waffle download web site: http://waffle.codehaus.org/download.html
  2. Download the latest Waffle stable version (E.g. waffle-distribution-1.0-beta-1-bin.zip)
  3. Create a waffle folder under C:\Program Files\ (or wherever you want)
  4. Unzip waffle-distribution-1.0-beta-1-bin.zip to C:\Program Files\waffle
  5. Extract to  C:\Program Files\waffle
  6. Open Eclipse WTP
  7. Create a New Project
    1. Select File/New/Project…
    2. Select Dynamic Web Project
    3. Click on Next>
    4. Select a Project name (E.g. helloWaffle)
    5. Make sure Apache Tomcat 5.5 is selected as the Target Runtime
    6. Click on Finish
  8. Add waffle lib to the build path
    1. Select User Library
    2. Select User Library
    3. Click Next>
    4. Click on User Libraries…
    5. User Library name: waffle
    6. Click on OK
    7. Click on Add JARS…
    8. Select all jar files under <waffle_dir?/lib (E.g. C:\Program Files\waffle\waffle-1.0-beta-1\lib)
    9. Click on Open
    10. Click on OK
    11. Click on Finish
    12. A User Librry named waffle have been created and added to helloWaffle project build path.
  9. Create a Controller
    1. Create HelloWorldController
    2. Class Name: HelloWorldController
    3. Package name: com.hellopensource.waffle
    4. Click on Finish
    5. Add getGree getGreeting() to HelloWorldController class
    6. public String getGreeting() { 

       

              return "Hello World!"; 

      }

  10. Create a Registrar
    1. Create MyRegistrar Class
    2. Class Name: MyRegistrar
    3. Package name: com.hellopensource.waffle
    4. Click on Finish
    5. Add the following code to MyRegistrar
    6. package com.hellopensource.waffle;

       

      import org.codehaus.waffle.registrar.AbstractRegistrar;

      import org.codehaus.waffle.registrar.Registrar;

       

      public class MyRegistrar extends AbstractRegistrar {

           public MyRegistrar(Registrar delegate) {

                super(delegate);

           }

       

           public void application() {

                register("hello", HelloWorldController.class);

           }

      }

  11. Create a jpsx page - the View
    1. File name: hello.jspx
    2. Click on Finish
    3. Replace the generated code by the following code:
    4. <?xml version="1.0" encoding="UTF-8"?> 

      <html xmlns="http://www.w3.org/1999/xhtml" 

            xmlns:jsp="http://java.sun.com/JSP/Page"> 

       

      <jsp:output doctype-root-element="html" 

                  doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" 

                  doctype-system="http://www.w3c.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> 

      <jsp:directive.page contentType="text/html;charset=UTF-8"/> 

       

      <head></head> 

      <body> 

      <h1>${controller.greeting}</h1> 

      </body> 

      </html> 

  12. Update web.xml
    1. Open the current web.xml (located under WebContent/WEB-INF)
    2. Replace web.xml by the following content:
    3. <?xml version="1.0" encoding="UTF-8"?> 

       

      <web-app version="2.4" 

             xmlns="http://java.sun.com/xml/ns/j2ee" 

             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 

             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

       

        <display-name>Waffle Example</display-name> 

       

        <!-- 1. This is how an application registers its custom Registrar --> 

        <context-param> 

          <param-name>org.codehaus.waffle.registrar.Registrar</param-name> 

          <param-value>com.hellopensource.waffle.MyRegistrar</param-value> 

        </context-param> 

       

        <!-- 2. Waffle context listener (ServletContext and HttpSession) --> 

        <listener> 

          <listener-class>org.codehaus.waffle.context.pico.PicoWaffleContextListener</listener-class> 

        </listener> 

       

        <!-- 3. Waffle request filter (responsible for request level context) --> 

        <filter> 

          <filter-name>WaffleRequestFilter</filter-name> 

          <filter-class>org.codehaus.waffle.context.WaffleRequestFilter</filter-class> 

        </filter> 

        <filter-mapping> 

          <filter-name>WaffleRequestFilter</filter-name> 

          <url-pattern>*.action</url-pattern> 

        </filter-mapping> 

       

        <!-- 4. Register Waffle's FrontController servlet --> 

        <servlet> 

          <servlet-name>waffle</servlet-name> 

          <servlet-class>org.codehaus.waffle.servlet.WaffleServlet</servlet-class> 

          <init-param> 

            <param-name>view.suffix</param-name> 

            <param-value>.jspx</param-value> 

          </init-param> 

          <load-on-startup>1</load-on-startup> 

        </servlet> 

        <servlet-mapping> 

          <servlet-name>waffle</servlet-name> 

          <url-pattern>*.action</url-pattern> 

        </servlet-mapping> 

      </web-app> 

  13. Add waffle JAR files to WebContent/Web-INF/Lib
    1. Copy the waffle JAR files
    2. Paste it on WebContent/Web-INF/Lib
  14. Run hello.jspx on Toncat within WTP
    1. Select hello.jspx / Run as > Run on Server
    2. Click on Finish
    3. Rename the url (on WTP)  from http://localhost:8587/helloWaffle/hello.jspx to http://localhost:8587/helloWaffle/hello.action
    4. Press Enter

 

Next Steps:

 

Comments (0)

You don't have permission to comment on this page.