Home Struts Struts2.3.8 Downloading and Installing Struts 2.3.8
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Downloading and Installing Struts 2.3.8

Advertisement
This tutorial shows you how you can download installing and test hello world application that comes with Struts 2.3.8. Struts 2.3.8 is latest version of Struts and come with the promise of providing high performance. Let's start downloading, installing and testing the example.

This tutorial shows you how you can download installing and test hello world application that comes with Struts 2.3.8. Struts 2.3.8 is latest version of Struts and come with the promise of providing high performance.

In this tutorial we have also included the video of this process. Video will show you detailed instruction of doing the process.

This tutorial is very useful for the beginners looking for good tutorial to learn Struts 2 easily and quickly.

Let's start downloading, installing and testing the example.

In this video tutorial I will explain you how to download and install Struts 2 blank applications on Tomcat 7 Servlet container.

Here the is the video of the complete process:

Steps by Step tutorial

Step 1: Go to the the url http://archive.apache.org/dist/struts/ and download the struts-2.3.8-all.zip file as shown below:

Step 2: Extract the content of struts-2.3.8-all.zip file as shown below:

Step 3: Copy struts2-blank.war into webapps directory of tomcat as shown below:

Step 4: Start tomcat server

Step 5: Type http://localhost:8080/struts-blank in your browser and test the application. Below is the screen shot of the example application.

Step 6: View the code of HelloWorld.java

package example;

/**
 * Set welcome message.
 */
public class HelloWorld extends ExampleSupport {

    public String execute() throws Exception {
        setMessage(getText(MESSAGE));
        return SUCCESS;
    }

    /**
     * Provide default valuie for Message property.
     */
    public static final String MESSAGE = "HelloWorld.message";

    /**
     * Field for Message property.
     */
    private String message;

    /**
     * Return Message property.
     *
     * @return Message property
     */
    public String getMessage() {
        return message;
    }

    /**
     * Set Message property.
     *
     * @param message Text to display on HelloWorld page.
     */
    public void setMessage(String message) {
        this.message = message;
    }
}

Step 7: Understand the configuration in example.xml struts configuration file. Here is the code of the example.xml file:

 <action name="HelloWorld" class="example.HelloWorld">
<result>/example/HelloWorld.jsp</result>
</action> 

In the above configuration code HelloWorld is defined which is responsible for handling HelloWorld.action action. The message from the variable " private String message;" is displayed on the browser.

Step 8: Understanding jsp file.  The code of the jsp file (HelloWorld.jsp) is as follows:

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title><s:text name="HelloWorld.message"/></title>
</head>

<body>
<h2><s:property value="message"/></h2>

<h3>Languages</h3>
<ul>
<li>
<s:url id="url" action="HelloWorld">
<s:param name="request_locale">en</s:param>
</s:url>
<s:a href="%{url}">English</s:a>
</li>
<li>
<s:url id="url" action="HelloWorld">
<s:param name="request_locale">es</s:param>
</s:url>
<s:a href="%{url}">Espanol</s:a>
</li>
</ul>

</body>
</html> 

The code "<s:property value="message"/>" is used to display the message on the page.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 14, 2013

Related Tutorials

Ask Questions?    Discuss: Downloading and Installing Struts 2.3.8  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com