Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Create a class to store the welcome message (the model)
  2. Create a server page to present the message (the view)
  3. Create an Action class to control the interaction between the user, the model, and the view (the controller)
  4. Create a mapping (struts.xml) to couple the Action class and view
    Tip

    By creating these components, we are separating the work flow into three well-known concerns: the View, the Model, and the Controller. Separating concerns makes it easier to manage applications as they become more complex.

    Let's look at an example model class, Action, server page, and mapping. If you like, fire up your Java IDE, and enter the code as we go.
    Info

    This tutorial assumes you've completed the How To Create A Struts 2 Web Application tutorial and have a working Basic_Struts2_Ant (or Basic_Struts2_Mvn) basic Struts project. The example code for this tutorial, Hello_World_Struts2_Ant or Hello_World_Struts2_Mvn, is available on Google Code - http://code.google.com/p/struts2-examples/downloads/list. After downloading and unzipping the file, you'll have a folder named Hello_World_Struts2_Ant (or Hello_World_Struts_Mvn). In that folder will be a README.txt file with instructions on now to build and run the example applicationhello_world, is available for checkout from the
    Struts 2 subversion sandbox at https://svn.apache.org/repos/asf/struts/sandbox/trunkImage Added. The example projects use Maven
    to manage the artifact dependencies and to build the .war files.

The Code

Let's modify either the Basic_Struts2_Ant or Basic_Struts2_Mvn basic_struts project to add a model class to store our message, a view that displays our message, an Action class to act as the controller, and a configuration that ties everything together.

...