簡體   English   中英

jsp:forward 標簽轉發到 Struts 2 動作

[英]jsp:forward tag forwards to Struts 2 action

我正在將一個 Struts 應用程序遷移到 Struts 2。它是四年前由 Struts 1.2 開發的。

我的問題是:

在我的JSP中,有這樣一個語句:

<jsp:forward page="/a.do" />

它在 Struts 1 中運行良好,但在 Struts 2 中不起作用,當我訪問這個 JSP 文件時它告訴我 HTTP 404 錯誤。

但是,如果我訪問http://localhost:8080/shell/a.do ,它運行良好。

我想知道原因,是不是因為向前動作不能被 Struts 2 過濾器捕獲? ( org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter )

那么前鋒不能分派到 Struts 2 動作?

我的應用程序中有很多轉發,如果轉發不能在 Struts 2 中工作,它是使用重定向而不是轉發的唯一解決方案嗎?

其實這個問題是基於我的分析,原來的工作是顯示網站的歡迎頁面。 如果我使用jsp:forward轉發到a.do ,它就不起作用。

我聽從了 Roman 的建議,使用result而不是 forward。 那么現在的問題是如何配置整個應用的默認動作呢?

我嘗試<default-action-ref name="a"/> ,但它僅適用於未映射的操作,例如http://localhost:8080/shell2/(some-unmapped-action).do ,它轉到默認動作。 但如果我不指定".do"它將不起作用。

當然這可以通過 url-rewrite 來完成,但我不想使用這種方法。

包含struts標簽庫

<%@ taglib prefix="s" uri="/struts-tags" %>

你可以簡單地在你的jsp頁面中寫下一些動作

<s:action name="YourAction" namespace="/PackageNamespace" executeResult="true" />

Struts 1 的forward概念轉移到dispatcher result的概念。 您必須從應用程序中刪除所有forward並創建result

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM