Use Struts2 for configuration

Source: Internet
Author: User

Use Struts2 for configuration

Important statement: the struts-2.3.15.3 version is used to learn struts2. If you have any problems with other versions, contact me.

I,

1. First, open myeclipse and create a project named struts001.

2. Copy 6 jar packages from the lib package of the downloaded struts-2.3.15.3 package:

Role of commons-fileupload-1.3.jar: File Upload

Role of commons-io-2.0.1.jar: Secondary File Upload

Freemarker-2.3.19.jar role: template engine

Role of ognl-3.0.6.jar: Support for struts2 ognl Language

Role of struts2-core-2.3.15.3.jar: struts2 core package

Role of xwork-core-2.3.15.3.jar: struts2 kernel package

Go to the lib file under the project path WebRoot.

3. Modify the web. xml file under the project to add:

Note: If you want to copy something in future projects, try to copy it, instead of spelling it as self-righteous. Many of the problems encountered by beginners are caused by misspelling of English words. Exercise caution in spelling.

  
   
  
   
Struts2
    
    
  
   
Org. apache. struts2.dispatcher. ng. filter. StrutsPrepareAndExecuteFilter
    
   
   
  
   
Struts2
    
  
   
/*
    
 

/*: Servlet knows that this is a form of receiving requests. This configuration means that all requests to access this project will be sent to StrutsPrepareAndExecuteFilter for processing. That is, struts2 controls the processing.

4. Configure struts. xml

Path: struts-2.3.15.3 \ apps \ struts2-blank \ WEB-INF \ classes

The struts2-blank is the war package under the app, you can modify the suffix zip and then unzip

Copy it to src.

The content can be viewed in my uploaded projects.

5. Create a class under src with the file name LoginAction. For details, see the files in the upload project.

6. Create loginUI. jsp and login. jsp under the WebRoot directory. For details, see the files in the upload project.

The action in form in loginUI. jsp must be the same as the name in the action configured in struts. xml.

7. Run the project, test,

8. Caused by: java. lang. IllegalArgumentException: Javassist library is missing in classpath! Please add missed dependency!

Because the javassist-3.11.0.GA.jar is missing, it can be found in the war package decompressed under the app. Originally, the javassist-3.11.0.GA.jar belongs to ognl. jar but was stripped, so it should be added separately.

9. Appearance: Caused by: java. lang. ClassNotFoundException: org. apache. commons. lang3.StringUtils

Because the lack of commons-lang3-3.1.jar.

10. The el expression in jsp is invalid due to the Tomcat 5 I used. Add the following at the top of the page:

<% @ Page isELIgnored = "false" %>. You do not need to configure Tomcat 5 or later.

12. Now the project is running normally.

2. You only need to follow these steps to configure the basic struts configuration.

Iii. Experience:

1. When naming files, classes, and other names in the project, it is best to use English. If not, you can translate them in a proper way.

2. You are advised not to spell something that can be copied by yourself. If you have to spell something, check it several times. When a beginner fails to write a program, first check the spelling.

3. The action class under Src should end with Action.

4. if you encounter bugs in the project, do not worry. Analyze the project from the ground up with a code record. The problem is located.

The configuration of struts2 is not planned to be discussed, but after all, it is the first time to write such a text, and there is no idea. Through this configuration, it is found that it is also a good mode to explain knowledge points through projects. Therefore, this method will be used in subsequent struts2 studies. During this period, I will add errors-prone explanations and my personal experience in analyzing and solving problems. If you have any problems that cannot be solved, contact me to solve them.

Happy every day:

Zhuge Liang directs the operation, and each time he takes a chariot to follow the army.

There was a war. Just as soon as the war started, the light drove the lead to the enemy.

The morale of the army was high, followed closely by the enemy. Post-war

Everyone likes: "The military is brave !"

Bright Road: "Hey, the slope is too oblique and you didn't stop the car ......"

The right to final interpretation belongs to partner aishang. Please indicate the source for reprinting.

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.