一、struts2的下載地址:http://struts.apache.org java
解壓下載的jar 到lib文件夾下找到全部的jar web
二、新建一個web項目,struts2-blank/web-inf/classes/lib所有拷貝下來apache
三、strut2的默認配置文件是struts2.xml,該文件須要放在web-inf/classes app
解壓下載的struts2文件夾下找到apps/struts2-blank.war,解壓此demo,打開struts2-blank/web-inf/classes/sturts.xml找到其模版jsp
<?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> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/WEB-INF/jsp/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error"/> </global-exception-mappings> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> <include file="example.xml"/> <!-- Add packages here --> </struts>
四、到struts2-blank/web-inf/下找到web.xml,把struts2的初始化啓動拷貝到本地項目的web.xml中(即:filter)url
<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>
配置啓動項的時候 2.1.3 之後org.apache.struts2.dispatcher.ng.filter.FilterDispatcher已通過時spa
配置這個類 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter便可code
Struts2讀取到struts.xml的內容後,以javabean形式存放在內存中,之後strut2對用戶的每次請求處理講是使用內存中的數據,而不是每次都讀struts.xmlxml
啓動項目,struts2搭建完成內存