Getting started with Struts2 and setting up the environment

Source: Internet
Author: User

Getting started with Struts2 and setting up the environment
Installation and setting

1. Decompress struts2.1.6. Assume that the extracted file is in the d: \ struts2 directory.

2. Install MyEclipse. Any version can

3. Assume that you have installed jdk and tomcat, for example, d: \ tomcat.

HelloWorld

1. Create a project

A) Open eclipse

B) create a project

C) Select myeclipse-java enterprise projects-web project

D) Project name: struts2_0100_introduction

E) Select java ee 5.0

 

2. Set server

A) window-preferences-myeclipse-servers-tomcat-6.x

B) Select tomcat home directory

C) Select enable

D) finish

 

3. Set the jdk Environment

A) window-preferences-java-installed jres

B) If no corresponding JDK (not JRE) exists, select add

C) select standard VM-> next

D) Select the Directory corresponding to JDK

E) set the JDK you just set to the default one.

 

4. Create the first struts2.1 Program

A) Find the corresponding apps directory under the struts directory

B) unzip the struts2-blank-2.1.6.war

C) Copy the corresponding lib jar file. All files except junit and spring-test are required. The commons-io jar package will be required during file upload and download, others are required

D) Copy the corresponding struts. xml file to the src directory and operate it in the package explorer view.

E) comment out the extra content of struts. xml.

F) Create a HelloStruts2_1.jsp file.

G) * modify the default encoding attribute of the jsp file window-preferences-web-jspfiles-set to Chinese, National Standard

H) configure the original configuration in struts. xml.

I) modify the corresponding web. xml and create a filter for struts2 (refer to the struts built-in Project)

 

5. Run the project

A) You can deploy the project on tomcat first.

B) You can also right-click the project debug as-myeclipse server app and select the server you just created.

 

6. Miscellaneous

A) the advantage of learning to establish the dev-mode of struts is that we can automatically hot replace it when modifying the configuration file.

B) Create the source code for the jar file D:/share/tools/struts-2.1.6/src/core/src/main/java and the source code for xwork, and the corresponding javadoc location (a better way is to build your own user-library)

C) view the struts directory

D) understand the eclipse jee project deployment directory and how to modify the context-root of webapp. problems may occur after the project copy is renamed.

E) package explorer-create a jar source file and target association, navigator-view all content

F) Recognize the extension of Action. In struts2 by default, it can be used without action.

 

 

FAQs:

 

1. the struts. xml prompt is not displayed automatically.

A) window-preferences-search catalog-add

B) Select the key type as URI.

C) key: http://struts.apache.org/dtds/struts-2.0.dtd

D) location: The corresponding dtd file, which is located in the struts-core package. Extract the file and specify the corresponding location, for example, D: \ share \ 0750_Struts2.1.6 \ soft \ struts-2.1.6 \ lib \ struts2-core-2.1.6 \ struts-2.0.dtd

 

2. Import sample projects

A) Pay attention to the JDK version, which should be JDK 6; otherwise, the class version problem may occur.

B) if there is always a problem with the project, you can recreate the project and copy files separately.

C) Right-click the project and select properties-java-compiler 6.0.

D) In addition, jdk6 should also be used in tomcat configuration.

3. If devMode is set to true, a null pointer may occur.

A) tomcat path with spaces

4. When ActionContext. getContext (). get ("request") is used, the object cannot be obtained. The value is null.

A) do not use the filter of 2.0 for web. xml. Use the new filter

5. encountered a strange bug in the action test

A) use default-action-ref to specify an action.

B) map * _ *

C) access a nonexistent action in the address bar, such as adfsdfsfs.

D) The result is mapped * _ *.

E) if it is changed to * _ *, no problem.

F) depends on, can only be considered as a bug

G) use *-* next time. Do not use *_*


 

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.