在Eclipse裡面配置Struts2

來源:互聯網
上載者:User

標籤:搭建   div   role   assign   dispatch   jar包   nbsp   this   desc   

下面介紹在Eclipse裡面配置Struts2

下載Struts2的壓縮包

我下載的是2.3.32版本

解壓之後

apps目錄:Struts2的範例

docs目錄:Struts2的文檔

lib目錄:Struts2的類庫

src目錄:關於Struts2的一些資源

在apps目錄下面有幾個例子

使用jar解壓

jar -xvf struts2-blank.war 

解壓之後得到

在struts-2.3.32\apps\WEB-INF\classes下找到struts.xml檔案

在Eclipse裡面配置Tomcat伺服器

我的機器上下載的是Tomcat9的包,所以配置Tomcat9

然後選擇你的Tomcat的位置。

配置完後是這樣

 

在Eclipse裡面建立一個web工程

 完成之後是這樣

將struts.xml檔案複製到Eclipse建立工程的src目錄下,在我的工程中如:

在解壓struts2-blank.war得到的WEB-INF目錄下開啟lib目錄,如:

 

將所有的jar包複製到建立工程Struts2Learn的WebContent的WEB-INF的lib目錄下,在我的工程中如:

在解壓struts2-blank.war得到的WEB-INF目錄下有web.xml檔案

檔案內容如下:

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" 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>Struts Blank</display-name>    <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>    <welcome-file-list>        <welcome-file>index.html</welcome-file>    </welcome-file-list>    <!-- Restricts access to pure JSP files - access available only via Struts action -->    <security-constraint>        <display-name>No direct JSP access</display-name>        <web-resource-collection>            <web-resource-name>No-JSP</web-resource-name>            <url-pattern>*.jsp</url-pattern>        </web-resource-collection>        <auth-constraint>            <role-name>no-users</role-name>        </auth-constraint>    </security-constraint>    <security-role>        <description>Don‘t assign users to this role</description>        <role-name>no-users</role-name>    </security-role></web-app>

將<filter></filter>和<filter-mapping></filter-mapping>元素複製到Eclipse建立工程Struts2Learn的web.xml檔案中,我的web.xml檔案如下所示:

在Eclipse中開啟複製來的struts.xml檔案,將檔案中<struts>和</struts>之間的內容注釋掉,並添加如下所示的代碼:

<package name="default" namespace="/" extends="struts-default">    <action name="hello">        <result>            /Hello.jsp        </result>    </action></package>

 

在Ecplise中建立一個Hello.jsp檔案,在<body>標籤之間寫如下代碼:

 

 

至此,開發環境初步搭建完成。

 

在Eclipse裡面配置Struts2

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.