I am migrating a struts application to Struts 2. It was developed by Struts 1.2 four years ago.
My question is:
In my JSP, there is such a statement:
<jsp:forward page="/a.do" />
It works well in Struts 1, but does not work in Struts 2, it tell me HTTP 404 error when I was accessing this JSP file.
However, if I access to http://localhost:8080/shell/a.do
, it works well.
I wonder the reason, is it because the forward action cannot be caught by the Struts 2 filter? (org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
)
So the forward cannot be dispatched to the Struts 2 action?
There are many forwards in my application, if forwards cannot work in Struts 2, does it the only solution to use redirect instead of forward?
Actually this question is based on my analysis, the original job is show welcome page of the site. If I use jsp:forward
forwards to a.do, it doesn't work. And I followed Roman's advice, use result
instead of forward. So the question now is how to configure the default action for the entire application?
I tried <default-action-ref name="a"/>
, but it works only for unmapped actions, for example http://localhost:8080/shell2/(some-unmapped-action).do
, it goes to the default action. But it does not work if I do not specify the ".do"
.
Of course this can be done with url-rewrite, but I don't want to use this approach.
Include the struts tag library
<%@ taglib prefix="s" uri="/struts-tags" %>
and u can simply write in ur jsp page to forword to some action
<s:action name="YourAction" namespace="/PackageNamespace" executeResult="true" />