Struts introduction

xiaoxiao2021-03-06  67

Turn one first!

1 JSP Framework - Struts Introduction Struts is a Framework for the open source of the web application using Java Servlet / JavaServer Pages technology.

The Struts can develop an application architecture based on MODEL-View-Controller design mode.

Struts has the following main features:

1. Contains a Controller Servlet to send the user's request to the corresponding Action object.

2. JSP Free Tag Library and provides association support in the Controller Servlet to help developers create interactive form applications.

3. Provide a series of practical objects: XML processing, automatically handle JavaBeans property, international tips, and messages through Java Reflection APIs.

Struts is part of the Jakarta project, homepage at http://jakarta.apache.org/struts.

Version 0.5 Download address: http://jakarta.apache.org/builds/jakarta-struts/release/v0.5

1.1 1, what is MVC mode. The MVC / View / Controller mode is a more design pattern that has been used abroad, as if the earliest is in Smaltalk. MVC includes three types of objects. Model is an application object, and the view is its representation on the screen, and the Controller defines the user interface to respond to the user input.

1.2 2, do all JSP applications use MVC mode? Not necessarily all JSP applications should be used in MVC mode. But for large applications, I think it is still using MVC mode. User interface interface is often mixed with these objects, while MVC separates them to improve flexibility and reuse.

1.3 3, can Struts do XML? What is the advantages compared to Cocoon? Struts puts the main energy on the JSP. CoCoon is a professional-grade XML Framework.

2. Struts installation 2.1 Install the software required for Struts

Java Development Kit - You need Download and Install 1.2 (or after) JDK. Download address: http://java.sun.com/j2SerseRvlet Container - The usual selection is to download Tomcat (at least version 3.1, recommended using version 3.2). Download address: http://jakarta.apache.org/tomcatant building system - If you install the package through the Struts Source Code, you must download the 1.1 or later version of the Ant Build System. In your own web app, you also recommend using Ant to build your application. Download address: http://jakarta.apache.org/antservlet API Classes - To compile Structs yourself, or the application uses Struts, you need a servlet.jar package with the servlet and JSP API objects. Most servlet containers (such as Tomcat) have come with this file. Otherwise, you must download: http://jakarta.apache.org/builds/jakarta-servletapixml Parser - Structs requires an XML processor compatible with the Java API for XML Parsing (JAXP) specification. I recommend using Xerces. Download address: http://xml.apache.org/xerces-jxalan 帖子  - If you construct your Structs system via Structs source code, you must download and install 1_2_d01 or later version of the Xalan XSLT processor (Xerces It has been brought to Xalan. This processor is used to convert XML-based Structs documents to HTML documents. ? 2.2 Construct Structs via the source code

1. Download the Structs source code release package. 2. Set an ANT_HOME environment variable to point to your Ant directory. 3. Set the java_home environment variable to point to your JDK directory. 4. Set the servletapi_home environment variable, point to your servlet API directory (if your ClassPath already contains servlet.jar, you do not need to specify the directory) 5. Unpack the StruCTS source code package. 6. Go to the structs directory, run the following command :? ./build.sh Dist This command will create the Struts binary package, the directory is in ../ dist / structs (relative to your compilation directory). ?

2.3 Install Structs by binary release packages through Struts

1. Download the Struts binary release. 2. Unpack the Struts binary release. (If you construct struts through the Struts source code, the result of Build is already unconnected Struts). The unproved Struts contains the following:? Lib / struts.jar - This file contains all Java objects for Struts. You need to copy it to your web-inf / lib directory for your web application. LIB / STRUCTS.TLD - This is a "Tag Library Descriptor" file that describes the free TAG of the Struts library. Need to copy it to the web-INF directory of your web application. WebApps / Struts-Documentation.war - This is a "Web Application Archive" file that contains all Struts documents. You can install it into the servlet container that supports Servlet API 2.2 or later (recommended using Tomcat). WebApps / Struts-Example.war - This is a web application instance that extensively demonstrates many features of Struts. You can install it into a servlet container that is compatible with servlet2.2 or later and the JSP1.1 or later version of the servlet container (recommended using Tomcat). WebAPPS / Struts-Test.war - This web application contains many TAG test web pages supported by Struts, which can be used as an example of using the Struts Tag. You can use Struts: 1 in your own application with the following steps. Copy the Struts Directory Lib / Struts.jar to the web-inf / lib directory of the web application. 2. Copy the lib / struts * .tld of the struts directory to the web-inf directory of the web application. 3. Modify the web-inf / web.xml file of the web application directory, add one

Element to define controller servlets, add one

Elements to establish a correspondence between the URI request to the servlet. You can refer to the web-inf / web.xml file in the Struts example to learn more about grammar requirements.

4. Modify the web-inf / web.xml file for the web application directory so that the following Tag library definitions are included:

???????

??????????

/Web-inf/struts.tld

??????????

/Web-inf/struts.tld

???????

???????

??????????

/Web-inf/struts-bean.tld

??????????

/Web-inf/struts-bean.tld

???????

???????

??????????

/Web-inf/struts-logic.tld

??????????

/Web-inf/struts-logic.tld

???????

5. Create a web-inf / action.xml file to define the Action mapping of your web app. You can refer to the Action.xml file in the Struts example to learn more about grammar requirements.

6. Add the following Tag library definition to the JSP page using the Struts Tag library:

??????? <@ Taglib URI = "/ Web-inf / struts.tld" prefix = "struts"%>

??????? <@ Taglib URI = "/ Web-inf / struts-bean.tld" prefix = "bean"%>

??????? <@ Taglib URI = "/ Web-inf / struts-logic.tld" prefix = "logic"%>

7. Finally, don't forget to include the struts.jar file in the classpath when compiling the Java programs for your web application. ?

?

?

?

Posted on July 27, 2004 10:42 AM

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

New Post(0)