struts2 build environment

2010-04-23  来源:本站原创  分类:Java  人气:476 

Struts2 environmental requirements Apache Struts2 environmental requirements are as follows:

Servlet API 2.4


Java 5

Need to be reminded that, in the Struts will be used in the Annotation, so please upgrade to JDK version 1.5.

Environment to build Struts2

4.1Struts Download

From the browser type, you can see a list of various versions of Struts. Can be found from the next figure, and now Struts2.0 The latest version is 2.1.0, released in 2007, October 29.

struts2 build environment

(Figure 1)

struts2 build environment

(Figure 2)

As can be seen from Figure 2, which can separate download, but also can be downloaded all at once. All the download size 83M,

The following table indicated the role of various compression packages.

Archive name


Document, contains the Struts2API

Required for the project to build Struts2 package

All the source code for Struts2


Blank Project

Great integration, including the contents of all of the above

Introduction 4.2 Development Tools

Currently J2EE development tools Eclipse and NetBeans can be divided into two camps, Eclipse the highest version 3.3, NetBeans version 6.0 of the maximum. Who has just seen from the news, NetBeans6.0 English the official version of the official release, and it is gratifying to HE.

The author mainly during development with Eclipse, but Eclipse does not support the WEB development, need to install the appropriate plug-in. MyEclipse is a powerful and framework to support a very wide range of WEB development of plug-ins, the product is fees. The maximum current MyEclipse version 6.0, but even so, it was not supported Struts2.0, we can manually configure the Struts2.0 development environment.

4.3 library file

Downloaded from the web site contains between twenty and thirty Struts2 libraries, but most are optional, and some libraries are plug-ins, and other frameworks for integration.

Readers are free to download the struts2-blank-2.1.0.war compression package, after the commencement of a very simple project, can be seen from the WEB-INF/lib directory of five library files, explained as follows:

Package Name



Log Management


Presentation layer framework that defines the visual component struts2 theme (theme)


OGNL expression language, struts2 support of the EL


struts2 core library


webwork's core library, the natural need for its support

struts2 build environment
(Figure 3)

4.3 using the Eclipse development environment to build Struts2 to create a user library 4.3.1

Struts2 package will be needed to build user base, you can more easily manage and use, this is a good habit - habit of programming from the beginning.

1. Select the menu Window-> Preferences-> Java-> Build Path-> User Libraries. Figure 4:

struts2 build environment

(Figure 4)

2. Click on the right side of the New ... button to create a new user base, pop-up dialog box as shown in Figure 5:

struts2 build environment

(Figure 5)

3. Enter the user name of the database, such as: Struts2, click the OK button, the dialog box automatically closes. The results shown in Figure 6:

struts2 build environment

(Figure 6)

At this point, the right button is lit.

4. Click "Add JARS ..." button, add the user base needed library files, Struts2, at least to include the above mentioned five library file. Add the following results as shown in Figure 7:

struts2 build environment

(Figure 7)

5. Click "OK" to complete.

4.3.2 The development of the first one Struts2 application - the world, Hello

Development of WEB applications, this article uses the MyEclipse plug-in. The plug-in for the billing software is currently available in English and Japanese versions, different versions can run on Windows, Linux and other operating system. For the convenience of the user, MyEclipse has a Full version, along with the Eclipse installation, for starters, can reduce a lot of trouble and distress.

Readers are free to download shared version of the software. Readers are advised to download the MyEclipse5.5 (which is the version I used), this version is relatively stable, MyEclipse6.0 still in beta.

Getting Started tutorial always HelloWorld as a first step in learning, natural writer is no exception. This example from the browser enter the URL, submit a request to display the page after the "Hello, world" message.

1. New WEB project, as shown in Figure 8:

struts2 build environment

(Figure 8)

2. Click "Next", enter the project name, as shown in Figure 9:

struts2 build environment

(Figure 9)

3. Click "Finish" to complete.

4. Struts2 libraries will now be imported into the project, right-click the project name pop-up shortcut menu, choose Build Path-> Add Libraries ..., as shown in Figure 10.

struts2 build environment

(Figure 10)

5. From the pop-up dialog box, select "User Libraries", as shown in Figure 11.

struts2 build environment

(Figure 11)

6. Click Next, we have seen above, a user created library appears in the list, in the "Struts2" before ticking the box on, click on "Finish" to complete. Figure 12.

struts2 build environment

(Figure 12)

7. The Struts2 filter org.apache.struts2.dispatcher.FilterDispatcher brought to the project's web.xml configuration file, by default, the filter string in order to intercept the request. Action at the end of the request, and that the Request delegated to the specified Action for processing. The performance of the most intuitive is to call the Action's execute () method. Code is as follows:

Code Listing 1: web.xml











Note: In Sturts1.X in the act be completed by the Servlet.

8. To create package com.lizanhong.action, and in the package to create HelloWorldAction class that inherits from the com.opensymphony.xwork2.ActionSupport. In theory, Action may not inherit any class or implement any interface to enhance the testability program, which is, and Struts1.X different places. However, inherited from ActionSupport coding can be reduced more.

The ActionSupport, the definition of the method execute (), when a user send a request to the Action will be automatically invoked. Code is as follows:

Code Listing 2:

package com.lizanhong.action;

import com.opensymphony.xwork2.ActionSupport;

publicclass HelloWorldAction extends ActionSupport {


public String execute() throws Exception {

System.out.println("Action Perform a .");




Note: ActionSupport is Struts2 provides classes, functions similar to the Struts1.x in the Action class that encapsulates several useful features, such as:

getText (): from the resource file, access to international technology news.

addFieldError (): validate input does not pass an error message when you add in support of internationalization.

execute (): This method will generally be rewritten, when the client sends a request to the Action, we will call this method.

To sum up, the class mainly provides the error messages of support and international support.

Created under the project classpath struts.xml document, which is the Struts2 configuration file, similar to Struts1.x in the struts-config.xml, in the struts.xml file can be configured to Action, Bean, Interceptor and other components.

Code Listing 3: struts.xml

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "">


<include file="struts-default.xml"></include>

<package name="a" extends="struts-default">

<action name="helloworld">





NOTE: WEB application's class path is the WEB-INF/classes directory, in Eclipse, create the file in the src directory after the final release will be automatically copied to the WEB-INF/classes directory.

Code Listing 3 involved in a lot of labels, the following is a simple explanation:

Tag name



Include other xml files, in the example, this means that can be accessed struts.xml defined in struts-default.xml file in the component.

The element can make Struts2 define multiple configuration files, "divide and rule."

It should be noted that any one struts2 configuration files and struts.xml should have the same format, including the doctype, and can be placed anywhere in the class path.


Stopped or cut-off device for the Action Group.

name: name, required, the name of the custom, no special requirements. To facilitate reference to other package.

extends: package could inherit the other package, that is achieved through the property, the value of another package's name.

In the example, extends = "struts-default" from the struts-default.xml in the inheritance.


The definition of Action, name attribute name used for the visit, class attribute is the class name of Action.


According to the definition of the return value of Action page navigation.

Action of the pre-defined return values are:

String SUCCESS = "success";

String NONE = "none";

String ERROR = "error";

String INPUT = "input";

String LOGIN = "login";

For example, when the Action returns SUCCESS when you want to go to ok.jsp page, you can read:

<result name="success"> ok.jsp </ result>

One, name of the default for success.

9.result.jsp is a very simple jsp page, the output "Hello, world."

Code Listing 4: result.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">



<base href="<%=basePath%>">

<title>My JSP 'result.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">


<link rel="stylesheet" type="text/css" href="styles.css">




Hello world, . <br>



9. Published works in the browser, type: http://localhost:8081/Struts2Demo/helloworld.action, in the console output "Action performed."

10. The result of the browser

struts.xml of the definition file

Code Listing 5: struts-2.0.dtd

<?xml version="1.0" encoding="UTF-8"?>

<!-- START SNIPPET: strutsDtd -->


Struts configuration DTD.

Use the following DOCTYPE


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"



<!ELEMENT struts (package|include|bean|constant)*>

<!ELEMENT package (result-types?, interceptors?, default-interceptor-ref?, default-action-ref?, global-results?, global-exception-mappings?, action*)>

<!ATTLIST package



namespace CDATA #IMPLIED


externalReferenceResolver NMTOKEN #IMPLIED


<!ELEMENT result-types (result-type+)>

<!ELEMENT result-type (param*)>

<!ATTLIST result-type



default (true|false) "false"


<!ELEMENT interceptors (interceptor|interceptor-stack)+>

<!ELEMENT interceptor (param*)>

<!ATTLIST interceptor




<!ELEMENT interceptor-stack (interceptor-ref+)>

<!ATTLIST interceptor-stack



<!ELEMENT interceptor-ref (param*)>

<!ATTLIST interceptor-ref



<!ELEMENT default-interceptor-ref (param*)>

<!ATTLIST default-interceptor-ref



<!ELEMENT default-action-ref (param*)>

<!ATTLIST default-action-ref



<!ELEMENT global-results (result+)>

<!ELEMENT global-exception-mappings (exception-mapping+)>

<!ELEMENT action (param|result|interceptor-ref|exception-mapping)*>

<!ATTLIST action




converter CDATA #IMPLIED


<!ELEMENT param (#PCDATA)>

<!ATTLIST param



<!ELEMENT result (#PCDATA|param)*>

<!ATTLIST result




<!ELEMENT exception-mapping (#PCDATA|param)*>

<!ATTLIST exception-mapping





<!ELEMENT include (#PCDATA)>

<!ATTLIST include




<!ATTLIST bean








<!ELEMENT constant (#PCDATA)>

<!ATTLIST constant




<!-- END SNIPPET: strutsDtd -->


Struts is a very popular nowadays by many enterprise-level WEB applications used in the framework, Struts2 in Struts1.x on the basis of a large number of transformation, and WebWork merged, the introduction of more new ideas, new ideas and new technology to make it more in line with J2EE application development needs.

"CPU benefit his tools" to master one or two development tools, can greatly enhance the programming efficiency, but also can enhance the developer's confidence. To learn a new technology, the first application is very important, if the first one of the most simple program to run is not successful, would make the learner's enthusiasm greatly reduced, which is I do not want to see. Therefore, this chapter describes in detail illustrated Struts2 application development process and as few as possible references to unfamiliar concepts and terminology.

Detailed reference:

  • struts2 build environment 2010-04-23

    Struts2 environmental requirements Apache Struts2 environmental requirements are as follows: Servlet API 2.4 JSP API 2.0 Java 5 Need to be reminded that, in the Struts will be used in the Annotation, so please upgrade to JDK version 1.5. Environment

  • Android build environment (change) 2009-12-16

    Android build environment itself is complex, and unlike the common build environment: only the top-level directory only Makefile file, while others use a unified standard for each component of the file itself is relatively simp

  • Configuring Build Environment for Flexmojos 2010-08-01

    Website: 20.2. Configuring Build Environment for Flexmojos Before you attempt to compile Flex libraries and applications with Maven, you will need to complete two con

  • (Struts2) IDE + environment configuration 1 2008-12-11

    Has recently learned some of Struts2 tutorial, in order to consolidate what knowledge, it is a bit on the end of each school to write some of the aspects of things, if there is an error of the Department asked a variety of exhibitions. Today, we firs

  • JDK + Tmocat for linux build environment 2010-03-24

    A need to source package: JDK: jdk-1.6.0_01-linux-i586.bin Tomcat: apache-tomcat-6.0.16.tar.gz 2, JDK installation and configuration of environment variables: 1. Installation: # Modify the file executable permissions # Chmod 755 jdk-1.6.0_01-linux-i5

  • Gxt-2.2.0 build environment for our first simple program up and running 2010-09-12

    Recent gxt interest, it is a Rich Application Client, the interface is very beautiful, so try to set up the environment today, a program up to their own. I was gxt is gxt-2.2.0, gwt gwt-2.0.4 version is. Introduce my development tools are Myeclipse8.

  • Java Web Development with Maven build environment (Jetty container) of 2010-10-13

    Maven is a Java application built an excellent management tool, is the top-level Apache Software Foundation projects. Build its catalog with the development and management, unified management third-party dependencies, compile, test, packaging, publis

  • J2ee build environment under Linux 2010-10-14

    View: Unix in echo $ PATH echo $ JAVA_HOME Here to talk about how to install JDK environment. JDK Download First, from the following link to download the latest JDK version: Now linux version is jdk-6u1-

  • Java Web Development with Maven build environment (Jetty container) 2010-10-14

    Maven is a Java application built an excellent management tool, is the top-level Apache Software Foundation projects. Build its catalog with the development and management, unified management third-party dependencies, compile, test, packaging, publis

  • Windows-based iPad / iPhone development build environment 2010-12-02

    Aspects of the company to do ios development, intended to look on xp now, the current operating system in windows application development iOS 5 kinds of optional programs. Method One: Black Apple Black Apple - is that not the Apple Computer (general

  • Introduction rails (1) build environment 2011-04-26

    Article Source: Transfer from: Then pick up the time that has come to Rails 3.0.3, the huge change that can not find tutorial to find articles in Chinese, has de

  • win7 python build environment under 2011-05-04

    Remember to build in ubuntu python development environment also under several commands, and who knows the system is not so easy to use into ubuntu11.04 toss a half-day did not do a good job, but to build in the next win7. Found a bit of trouble to re

  • ubuntu11.04 php build environment under 2011-05-05

    This is just to build a basic environment, execute the following command sequence is very simple: sudo apt-get install apache2 sudo apt-get install mysql-server sudo apt-get install php5 libapache2-mod-php5 php5-mysql Finally, a soft link to / var /

  • vmware, ubuntu linux kernel build environment 2011-01-03

    Engage in a bit this weekend compiling the linux kernel, there are some records about the experience here, so easy to find later. Software environment: the main operating system Windows 7, the virtual machine software, vmware 7.0.0 build-203739, the

  • WTP build environment 2011-05-17

    Eclipse + WTP + Tomcat Java Web development environment to build 1. Download and install eclipse 2. Installing tomcat Download these two addresses do not say, it just Soso Using the WTP can download an all-in-one version, such as the wtp-all-in-one-s

  • Java build environment under Linux 2010-03-23

    First, install jdk my version is: jdk-6u10-linux-i586.rpm Install jdk1.6 installation package: rpm-ivh jdk-6u10-linux-i586.rpm Configure environment variables: 1, into the profile file: vi / etc / profile 2, in the file add the following code: export

  • Android Notes of a build environment 2010-06-09

    1.Installing the Android SDK Download the very latest SDK, see . Unpack the SDK Starter package to a location and then add the location ('D: \ Android-sdk_r06-Windows \ Android-SDK -windows \ tools') to PAT

  • Under windows build environment for Apache + MySql + Php 2010-07-12

    First, the environment WindowsXP Apache MySql PHP I downloaded the relevant versions were:, mysql-essential-5.1.

  • Distributed Token struts2 web environment reform 2010-07-23

    Recently read struts2 source, found under struts2 interceptor is based on the session's token Core category is org.apache.struts2.util.TokenHelper The page marked with labels into the token public static String setToken(String tokenName) { Map sessio

  • MinGW build environment 2011-05-22

    If MinGW installed in the D: \ Program Files \ MinGW under The first step: And in D: \ Program Files \ MinGW \ bin and a file under: mingw32-make.exe, this is actually make the file, you can copy a name change to make.exe, can also be directly change