Struts2的配置和使用
一:配置stuts2的運行環境,把以下的包放到WEB-INF/lib目錄下
1,structs2-core-2.1.6.jar struts的核心庫
2,xwork-2.1.2.jar webwork的核心庫,需要它的支持
3, ognl-2.6.11.jar ognl表達式語言,struts2支持改EL表達式
4,freemarker-2.3.13.jar 表現層框架,定義了struts的可視組件主題
5,common-logging-1.0.4 .jar 日子管理
6,commons-fileupload-1.2.1.jar 文件上傳于下載
二:struts2攔截用戶請求,在web.xml里面配置
<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></pre> <p></p>
三:在src目錄下配置struts.xml
內容如下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
";
<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">/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></pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!