Struts beginner guide

xiaoxiao2021-03-06  55

Struts should be no very new, don't know if there are any beginners need the following

First, Struts Introduction

Struts is a sub-project for the Apache organization JAKARTA project to improve the structure of the web system.

The Web system itself has a complexity and business process uncertainty, which is quite tricky and difficult to handle.

For example, users may always use a link from the system's part to another. Or log in again

After the page may not be reflected in a hurry, and suddenly request another service .........

If the Web system does not have a good design structure, these annoying problems can be wrapped in you until you crash,

Or the system crashes. Even if you have a few times, you can get you mad at the later maintenance work, or put it

Other maintenance people are mad! :)

MVC (Model - View - Controller) mode The most important idea is that the service code is separated from the view code.

It can effectively clear the system structure and reduce the difficulty of system complexity and maintenance.

Struts is based on J2EE's Web-form MVC mode implementation!

Of course, Struts is not just the case. It is mainly composed of two parts, one is the improvement above.

The MVC frame part of the web system structure. The other part is the label library of Struts, mainly from the web.

Page producer is used.

We mainly talk about the first part, some entry-level content, and some of the issues encountered.

Second, environmental configuration

We use Tomcat 4.1.29 Struts1.1 to do a demonstration.

Tomcat download address:

http://apache.linux process.net/dist/jakarta/tomcat-4/v4.1.29/bin/jakarta-tomcat-4.1.29.zip

Struts download address:

http://apache.linuxForum.Net/dist/jakarta/struts/binaries/jakarta-struts-1.1.zip

Add environment variables: (for example :)

Java_home C: /J2SDK1.4.2/

Tomcat_home C: / Tomcat /

At the same time, you also need to turn struts / lib / struts.jar, Tomcat / Common / lib / servlet.jar

The file is added to the classpath variable, and the code is compiled.

(Of course, there are more integrated environments such as Eclipse)

Run Tomcat /bin/startup.bat launch Tomcat

Tomcat test: http:// localhost: 8080 / Can see the cat is successful

Struts does not need to be configured at all

Download Struts download compression package, copy /webapps/struts-example.war file

Under Tomcat / WebApps / Directory, then restart Tomcat can test

Enter: http: // localhost: 8080 / struts-example / see the blue "struts" icon is OK.

Note: If you test the old unsuccessful, it is recommended to change the machine to try. The Java environment is too chaotic testing will fail? ! (I just took this day)

Third, instance demo

If the above configuration is done, we start to make a small presentation. Demo task is to do a user

Register / log in the site. About Struts demonstration, such user registration / login example is an old set.

I don't know if my example can arouse your interest. :)

First, build a subdirectory in Tomcat / WebApps / Directory Name StrutSdeMostrutsDemo's directory structure as shown

StrutsDemo off all .jsp page files

Copy the Struts Decompression Directory LIB / under all * .tld files to web-inf / down

These are Struts label library files, and our examples will be used.

Copy all the Struts directory lib / under all * .jar files to web-inf / lib / directory

Used. Jar bags must be released here, otherwise it will have a mistake in finding a resource.

(To do Struts related, at least you want to extract the Struts under the directory / lib .jar test over)

Web-INF / CLASSES / Directory (or under its sub-directory) also needs a .properties resource file

Used to support internationalization

The above is preparing a Struts engineering-based preparation work.

Originally planned to post code, limited to space providing code download, has included detailed notes

download:

Strutsdemo.rar

Fourth, the problem that beginners need to pay attention

(1) 2 .XML profiles are really annoying, especially those who directly use Notepad.

Be patient, the format must be correct, you can refer to the example of Struts.

(2) The validate field attribute of the acturn property in the struts-config.xml file needs to be set to "True"

Can you start the page detection of the Validate method corresponding to the Form

(3) STRTURS_CONFIG.XML configuration file "Scope field used to specify the activity of the action, the default value is" session ", so we generally set Scope to" Request ". If needed

For "session", pay attention to the reset () method of the FORM BEAN to restore the Form Bean initial value;

(3) How to make * _zh.properties Chinese resource files

Native2ascii tools under java_home / bin / directory

First make an ApplicationResources.properties file with Chinese writing information

Then the command line window type

Native2ascii -Encoding GB2312 ApplicationResources.properties

ApplicationResources_zh.properties

I can't think of it for a moment, and then add -___- !!

转载请注明原文地址:https://www.9cbs.com/read-117017.html

New Post(0)