1.在/WEB-INF/lib目录下,导入struts1的jar文件(在struts1的lib目录下);
2.修改/WEB-INF/web.xml(整个web项目的部署管理器),设置servlet,使其指向struts1的ActionServlet(中央控制器)
web.xml代码:
<?xml version="1.0" encoding="UTF-8"?>
- <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <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>
- <load-on-startup>0</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>action</servlet-name>
- <url-pattern>*.do</url-pattern>
- </servlet-mapping>
- </web-app>
其中如果config默认是在/WEB-INF下,并且名字为struts-config.xml的话,可以省略不写
3.到了struts的配置文件:struts-config.xml
例如:
1. <?xml version="1.0" encoding="utf-8" ?>
2.<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
3.<struts-config>
4.<form-beans>
5.<form-bean name="peopleForm" type="org.formbean.PeopleActionForm"></form-bean>
6.</form-beans>
7.<action-mappings>
8.<action path="/people" name="peopleForm" scope="request"
type="org.action.HandlePeopleAction" >
9. <forward name="success" path="/list.jsp"></forward>
10. <forward name="fail" path="/fail.jsp"></forward>
11.<forward name="modify" path="/modify.jsp"></forward>
12.</action>
13. </action-mappings>
14.<message-resources parameter="MessageResources" /><!-- 使用struts标签必须配置的东东 -->
15.</struts-config>