STRUTS2 Tutorial 1: The first STRUTS2 program

Source: Internet
Author: User

In this series of tutorials we will learn about the various techniques of Struts2. The following versions of the tools and libraries used in this tutorial are:

Development tools: MyEclipse6

Web server: Tomcat6

Struts version: Struts2.0.11.1

JDK version: Jdk1.5.0_12

Java EE version: EE5.0

The context path for the Web project in this series of tutorials is struts2, and if there is a index.jsp file in the Web root directory, the access path is as follows:

http://localhost:8080/struts2/index.jsp

Since MYECLIPSE6 currently does not support STRUTS2, we need to go to struts.apache.org to download the STRUTS2 installation package. For a normal use of Struts2, you need at least five packages (depending on the Struts2 version, the package name is slightly different, but the first half of the package name is the same).

Struts2-core-2.0.11.1.jar

Xwork-2.0.4.jar

Commons-logging-1.0.4.jar

Freemarker-2.3.8.jar

Ognl-2.6.11.jar

Struts2 is the second version on the big version, but basically it has completely overturned the struts1.x in terms of configuration and usage (STRUTS2 is still based on the MVC pattern, the action-driven, maybe it's the only thing that hasn't changed), though. Struts2 is actually an MVC framework built on a webwork basis. We can see from the source code of STRUTS2 that there are many packages that are directly used by Xwork (webwork core technology). Since STRUTS2 is technically a new framework, let's learn how to use this new framework.

If you have used struts1.x, you should be very clear about the basic steps of building a struts1.x Web program. Let's review the basic steps of building a struts1.x Web program.

1. Install struts. Because the entry point of Struts is actionservlet, this servlet has to be configured in Web.xml.

2. Write the action class (typically inherited from the Org.apache.struts.action.Action class).

3. Writing the Actionform class (typically inherited from the Org.apache.struts.action.ActionForm Class) is not necessary, and this step is required if you want to receive data submitted by the client.

4. Configure action and Actionform in the Struts-config.xml file.

5. If you want to collect data entered by users, you usually need to write a number of JSP pages, and through these JSP pages in the form of the data submitted to the action.

Here we will write the struts1.x program of these five steps and the struts2.x program of the writing process one by one corresponding to see who they are more "cool." Here we write a web-based program based on STRUTS2. The function of this program is to allow the user to input two integers, and submit to a struts Action, and calculate the algebra of these two numbers and, if the code and is non-negative, then jump to the positive.jsp page, otherwise jump to the negative.jsp page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.