Novice Learn the STRUTS2 environment configuration of the Java EE

Source: Internet
Author: User

Struts is one of the three most famous SSH frameworks, still playing an important role in the Java Web today, in the MVC mode, which is responsible for the various JSP pages and action scheduling control (Controller), the following is the basic configuration of Struts2 under Eclipse.

First, the preparatory work

1. Before the struts configuration, the Eclipse environment variables are configured by default and the Tomcat server is deployed;

2. Download the jar package required by STRUTS2.

    

Second, create a Web program, import the program required jar package

The JRE version I used is 8.0,TOMCAT version 7.0

1. Open Eclipse and create a new web Dynamic Project (take care to choose Tomcat's runtime);

2. Add the 7 struts jar packages in the first step to the Java build path: Select the project, click Projects >> Properties >> Java build Path, select the Libraries tab, click Add External jars adds 7 jar packages to the path;

3. It is not enough to add only the 7 jar packages mentioned above to the path, but also put them in the WebContent directory under the Web-inf Lib folder (this step is indispensable, configure hibernate later , spring is the same, many novice run the program when the error can not find the reason is ignored this step).

Note: Because of the struts2 version, the above jar packages do not necessarily meet the requirements of all editions. When you are finished configuring STRUTS2, run. Add a jar package to resolve the issue based on the runtime's error message. For example, Commons-io-1.3.2.jar packages and Javassist-3.7.ga.jar packages are required to configure struts-2.2.1.1, but these two packages are not required for version 2.1.

Iii. writing the Web. xml file and the Struts.xml file

1.web.xml in the Web-inf below the Lib folder, the creation of the project has been automatically generated, a little change can be;

    

If you press this Web. XML configuration file, the program runs from index.html in the WebContent directory (you need to add it yourself).

2.struts.xml files, placed in src directory

    

Add the action class in the middle of <package ......> </package>.

Iv. write Action class, add other JSP, HTML page

Add the action class in the middle of <package ......> </package>. The wildcard character for action as shown in step three is namespace= "/", the name is Login.action, corresponds to the login method in the Com.Action.UserLoginAction class, the method type is string, when the method returns "Success" , the program then jumps to the menu.jsp in the JSP directory and jumps to the signonform.jsp page when it returns "Nouser" and "error".

At this point, the basic configuration of STRUTS2 is complete, then you can continue to add other action classes in <package ......> </package> and add the corresponding JSP files under the corresponding folder to build your own Java Web program.

Novice Learn the STRUTS2 environment configuration of the Java EE

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.