1.导包java
2.在 src 目录下建立 struts.xml 文件web
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!--配置action的访问后缀--> <constant name="struts.action.extension" value="do,,"></constant> <!--修改struts配置后自动加载struts文件 不须要重启tomcat--> <constant name="struts.configuration.xml.reload" value="true"></constant> <package name="default" namespace="/" extends="struts-default"> <action name="employee" class="com.ww.struts2.action.EmployeeAction" method="success"> //配置action(Servlet)类 <result name="success">index.jsp</result> //name属性的值与action的execute方法的返回值对应 </action> </package> </struts>
3.在web.xml中配置struts过滤器apache
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>