1,导入Struts需要的jar包
<!-- Struts1导入开始 -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-el</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts-extras</artifactId>
</dependency>
<!-- Struts1导入结束 -->
<!-- Apache-Commons -->
<dependency>
<groupId>bsf</groupId>
<artifactId>bsf</artifactId>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
</dependency>
2,在web.xml中配置actionServlet,这里配置了多个Struts配置文件,config是默认,在config/model则是子模块,访问需要/model/dis.do?mm=add,还有一种是在config下同时配置几个路径,用','隔离,这不是子模块,初始化时Struts会把它们合成一个,而如果你要跨模块访问,需要在默认配置文件中配置switchaction,访问路径则是
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>config/model</param-name>
<param-value>struts1/model/struts-config-model1.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<!-- 服务器一启动Actionservlet就会启动 -->
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>regAction</servlet-name>
<servlet-class>com.platform_easyuiSSH.struts1.util.RegAction</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
3,配置struts-config.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<!-- name:ActionForm的名字,随便定义的 -->
<!-- type:ActionForm的全类名 -->
<!-- <form-bean name="tUser" type="com.platform_easyuiSSH.struts1.action.TeacherForm"></form-bean>
-->
<form-bean name="login" type="com.platform_easyuiSSH.struts1.action.form.LoginForm"></form-bean>
</form-beans>
<action-mappings>
<!-- path:客户端请求的路径 -->
<!-- name:ActionForm的名字 -->
<!-- type:Action的全类名 -->
<!-- attribute="login"保存属性的名字,没有则使用name -->
<!-- input="/views/struts1/login.jsp"错误后跳转的页面 -->
<!-- validate = "true"是否验证默认true -->
<!-- scope="request"action作用域 -->
<action path="/show" name="tform"
type="com.platform_easyuiSSH.struts1.action.UserAction">
</action>
<action
attribute="login"
input="/views/struts1/login.jsp"
path="/login"
name="login"
validate = "true"
scope="request"
type="com.platform_easyuiSSH.struts1.action.LoginAction">
</action>
</action-mappings>
<message-resources parameter="struts1/ApplicationResources"></message-resources>
</struts-config>
4,继承action,继承actionForm
5,常用高级Action,DispatchAction,MappingDispatchAction,LookupDispatchAction