用Myeclipse開發Struts框架web項目

1.打開myeclipse,點擊左上角File,選擇new,再選擇web project,視圖如下,文件名隨便起,我的名爲test01

2.結果如下


3.右鍵點擊test01文件,選擇Myeclipse,再選Project Facets,然後選Install Apache Struts(2x)Facet。此步可以導入struts的jar包。


4.導入後如下,可以看到在src文件夾新增加了文件struts.xml。而且web-inf中的web.xml也自動更新了。


5.打開struts.xml文件,在<struts></struts>標籤中加上<package>等內容。

<struts>  
         <package name ="welcomePackage" extends="struts-default">  
                <action name ="sun">  
                     <result >/index.jsp </result >  
                </action >  

        </package >  

</struts>

6.運行項目test01,你會發現結果如下,網址爲http://192.168.0.136:8080/test01/sun。原因是因爲沒配置web.xml


7.停止運行,打開web.xml.


8.點擊Source按鈕,此按鈕在上圖的左下角。改寫倒數第三行,改爲 <url-pattern>/*</url-pattern>


9,把鼠標移動到文字org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter上,然後按住Ctrl,此時文字變爲鏈接。點進去


10.點擊Attach Source...,點擊External localtion,然後點擊External Folder選擇文件夾src。此文件夾在Struts-2.3.15-all中。此文件的壓縮包在網站http://www.pan66.com/show/2003964.html。下載後解壓


11.導入後,會出現如下StrutsPrepareAndExecuteFilter.class


12.在次運行test01項目,輸入網址http://192.168.0.136:8080/test01/sun,結果如下。說明配置成功。他根據域名中的sun找到了文件index.jsp.


祝你成功