简体   繁体   中英

jsp:forward tag forwards to Struts 2 action

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 tells 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" />

The concept of forward from Struts 1 moved to concept of dispatcher result . You have to remove all forward s from your application and create result s instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM