We will mainly explain struts1.1. Here we assume that the reader has configured the Java Runtime Environment and the corresponding Web Container. In this example, j2sdk and atat4.1.27 are used. Next, we will introduce the basic part of step by step.
Install struts
To the http://jakarta.apache.org/download struts installation file, this example uses version 1.1.
Next, perform the following steps to complete the installation:
1. Unzip the downloaded installation file to your local disk.
2. generate a new Web application. Assume that the root directory of the generated application is /Webapps/mystruts directory. Create an alias for the application in the server. xml file, such as/mystruts.
3. Copy the following JAR files from the files decompressed in step 1 /Webapps/mystruts/WEB-INF/lib directory, the main files are as follows.
struts.jarcommons-beanutils.jarcommons-collections.jarcommons-dbcp.jarcommons-digester.jarcommons-logging.jarcommons-pool.jarcommons-services.jarcommons-validator.jar |
4. Create a web. XML file, which is a deployment description file required by servlet-based Web applications. A struts web application is essentially a servlet-based Web application.
Struts has two components to be configured in this file: actionservlet and tag library. The following is a configuration list:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"><web-app> <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>2</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib></web-app> |
Above we complete the basic configuration of Servlet and tag library in Web. XML, and more framework components need to be configured in struts-config.xml:
5. Create a basic struts-config.xml file and place it in /Webapps/mystruts/WEB-INF/directory, the file is based on the struts application configuration description file, it combines the components in the MVC structure, it is constantly enriched and changed during development. In struts1.0, an application can only have one such file, which makes Division of Labor Development inconvenient. In struts1.1, there can be multiple such files to overcome these shortcomings. The components to be configured in this file include: data-Sources
global-execptionsform-beansglobal-forwardsaction-mappingscontrollermessage-resourcesplug-in |
The configuration list is as follows:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><struts-config> <message-resources parameter="ApplicationResources" /></struts-config> |
So far, we have the various components required to complete the simplest struts application.