struts2設定index.action為首頁(另:web.xml編輯卡死問題解決)

來源:互聯網
上載者:User

標籤:style   c   class   blog   code   java   

本來是弄攔截器的問題,結果弄首頁的時候,還是發現了問題。

公司網站的項目裡面,是用index.action作為首頁的,訪問WEB-INF裡面的html檔案。可是我設定的卻不成功,追根到底,一個原因,struts2比較特殊,struts.xml裡面必須多配置一個request和response。

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" version="3.0" 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_3_0.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>                <dispatcher>REQUEST</dispatcher>         <dispatcher>FORWARD</dispatcher>      </filter-mapping>     <welcome-file-list>        <welcome-file>index.action</welcome-file>    </welcome-file-list></web-app>

這樣就可以便於使用index.action作為首頁。

另外這樣配置後,也可以用jsp裡面加forward來跳轉到index.action作為首頁。也可以用html裡面加一個<meta>標籤重新整理跳轉到首頁action裡面。

不經過request和response,只能用html加<meta>標籤的方式。

 

另:eclipse編輯web.xml的時候,總是卡死,是因為xml頭版本的問題,裡面的版本數字要一致。

<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_9" version="3.0" 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_3_0.xsd">

如上,都是3.0的。

聯繫我們

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