Struts2---環境搭建及包介紹


導入jar包

jar包下載地址:http://www.apache.org/官網中選擇struts,然后點擊download下載。將jar包導入到WEB-INF下的lib文件目錄下。

asm-5.2、asm-commons-5.2、asm-tree-5.2:反射的替代方案。asm是小巧便捷的java字節碼操控框架,它能方便的動態生成和改造java代碼

commons-fileupload-1.3.3:上傳文件

commons-io-2.5:對本地文件、流進行操作

commons-lang3-3.6:基礎文件包

commons-logging-1.1.3:日志包

freemarker-2.3.23:生成各種文本:html、xml、rtf、java源代碼等

javassist-3.20.0-GA:使java字節碼操控更加簡便,是一個編譯java字節碼的類庫,提高效率

log4j-api-2.8.2:日志

ognl-3.1.15:struts2獨有的標簽庫

struts2-core-2.5.13:struts2的核心包

復制struts.xml文件到src文件夾下任意位置

在沒網絡情況下,無法下載struts-2.5.dtd文件,從而無法進行代碼編寫提示。這種情況需要在IDE中手動配置,Window-->Preferences-->XML Catalog-->add-->key type:選擇URI;key:即下載struts-2.5.dtd文件的地址,也是struts.xml文件中DOCTYPE配置的地址-->File System:加載本地struts-2.5.dtd文件-->點擊添加

在web.xml文件中加入過濾器

<?xml version="1.0" encoding="UTF-8"?>
<!-- 設置代碼提示所需文檔位置 -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>StudyStruts2</display-name>
  <filter>     <filter-name>StrutsFilter</filter-name>     <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>   </filter>   <filter-mapping>     <filter-name>StrutsFilter</filter-name>     <url-pattern>/*</url-pattern>   </filter-mapping>
</web-app>

 

注意:這里加入過濾器是filter標簽,不是servlet標簽


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM