Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 324
LiuWenbin_NO. Avatar asked Apr 17 '13 09:04

LiuWenbin_NO.


People also ask

What does jsp forward do?

JSP forward action tag is used for forwarding a request to the another resource (It can be a JSP, static page such as html or Servlet). Request can be forwarded with or without parameter.

How do I redirect from one action to another action in struts2?

The redirect result type calls the standard response. sendRedirect() method, causing the browser to create a new request to the given location.

How to forward jsp to another jsp?

To forward a request from one page to another JSP page we can use the <jsp:forward> action. This action has a page attribute where we can specify the target page of the forward action. If we want to pass parameter to another page we can include a <jsp:param> in the forward action.


2 Answers

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" />
like image 111
MBR Avatar answered Oct 03 '22 12:10

MBR


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

like image 41
Roman C Avatar answered Oct 03 '22 11:10

Roman C