在Eclipse Helios 3.6.2上配置Struts2開發環境

來源:互聯網
上載者:User
1. 下載Eclipse
登入Eclipse官網下載http://www.eclipse.org/downloads/

我選擇的是Eclipse Classic 3.6.2, 32位

2. 添加Web and Java EE開發工具
Help -> Install new software,在"Work with:"下拉框中選中"Helios - http://download.eclipse.org/releases/helios"(如果沒有,可以自行添加),然後在"Web, XML, and Java EE Development"中選擇

  - Eclipse Java EE Developer Tools
  - Eclipse Web Developer Tools
  - JST Server Adapters (建立Apache Tomcat Server需要)

3. 下載Tomcat
登入Apache Tomcat官網下載http://tomcat.apache.org/

我選擇的是Tomcat 7.0.14

4. 添加Tomcat外掛程式
http://www.eclipsetotale.com/tomcatPlugin.html

這個好像沒有官網,也沒有update site
下載後解壓,複製到plugin目錄下,然後重啟eclips即可

5. 建立Web工程
File -> New -> Project -> Dynamic Web Project

6. 添加Struts 2類庫
登入Struts官網下載http://struts.apache.org/downloads.html

我選擇的是struts-2.2.3-lib.zip
下載後解壓,把Struts 2必須的核心類庫複製到到Web工程的WebContent/WEB-INF/lib下
  - commons-fileupload-1.2.2.jar
  - commons-io-2.0.1.jar
  - commons-lang-2.5.jar
  - commons-logging-1.1.1.jar
  - freemarker-2.3.16.jar
  - javassist-3.11.0.GA.jar
  - ognl-3.0.1.jar
  - struts-core-1.3.10.jar
  - xwork-core-2.2.3.jar

7. 建立web.xml
不知道為什麼,工程建立的時候沒有web.xml,不過沒有關係,我們可以自己建
檔案位置:/WebContent/WEB-INF/web.xml
內容 Xml代碼
 

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app id="WebApp_ID" version="2.4"  
  3.     xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  5.   
  6.     <display-name>Project Name</display-name>  
  7.     <welcome-file-list>  
  8.         <welcome-file>index.html</welcome-file>  
  9.     </welcome-file-list>  
  10.   
  11.     <filter>  
  12.         <filter-name>struts2</filter-name>  
  13.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  
  14.     </filter>  
  15.   
  16.     <filter-mapping>  
  17.         <filter-name>struts2</filter-name>  
  18.         <url-pattern>/*</url-pattern>  
  19.     </filter-mapping>  
  20.   
  21. </web-app>  
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4"xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><display-name>Project Name</display-name>    <welcome-file-list>        <welcome-file>index.html</welcome-file>    </welcome-file-list><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>

8. 建立struts.xml
檔案位置:/WebContent/WEB-INF/classes/struts.xml

內容 Xml代碼
 

  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC   
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"   
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5.   
  6. <struts>  
  7.   
  8.     <package name="default" extends="struts-default">  
  9.         <action name="action_name" class="package_name.class_name">  
  10.             <result name="Success">./WEB-INF/jsp/success.jsp</result>  
  11.             <result name="Failure">./WEB-INF/jsp/failure.jsp</result>  
  12.         </action>  
  13.     </package>  
  14.   
  15. </struts>  
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <package name="default" extends="struts-default">        <action name="action_name" class="package_name.class_name">            <result name="Success">./WEB-INF/jsp/success.jsp</result>            <result name="Failure">./WEB-INF/jsp/failure.jsp</result>        </action>    </package></struts>

9. 建立Server
File -> New -> Server
"Server Type"我選擇了"Tomcat v7.0 Server",然後把建立的Web工程移動到"Configured"中就可以了

這樣基本就搭建好Struts 2的結構了 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.