這幾天的項目頁面的訪問全部改為.action訪問,在修改首頁時遇到了問題。將web.xml文件中<welcome-file>index.action</welcome-file>修改成這樣,訪問首頁時報404錯誤,也就是說文件找不到。上網查了有兩種解決方法。
方法一、在WebRoot下新建一個index.action空文件,這個方法簡單實用,強烈推薦。
方法二、因為 welcome-file 必須是實際存在的文件,不能是action或者servlet路徑你可以設置一個 比如 <welcome-file>goindex.jsp</welcome-file>,然后 goindex.jsp 寫 <jsp:forward page="index.action" /> 就行了。意思就是借助一個jsp頁面來轉發請求進入action。
方法三:在index.html中使用META重定向。
操作:<META HTTP-EQUIV="Refresh" CONTENT="0;URL=max/HelloWorld.action">
其中,
content="1 是時間控制,表示1秒后自動跳轉到要跳轉的頁面.
content="0 表示打開該頁后立即跳轉到你要跳轉的頁面.
url 是要跳轉的路徑
——————————————————————————————————————————————
在struts2中還很特別:
原因:
因為struts2采用過濾器的方式處理請求,默認情況時監控url地址的變化
必須如下操作:
第一步:
web.xml中修改
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern >/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
第二步:
web.xml中添加
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
第三步:
首頁跳轉語句
index.jsp內容如下:
<jsp:forward page="HelloWorld.action"></jsp:forward>
或者采用方法三!!!
來自:http://blog.sina.com.cn/s/blog_4b5bc0110100yrn2.html