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>