kaqqao
kaqqao

Reputation: 15429

Struts 1, redirect works ok but forward gives 404

In a Struts action, if I return an ActionForward with a redirect flag set to true, everything works as expected, i.e. the request ends up on the desired page. But, when I set redirect to false, it results in 404. It's important to note, I'm not redirecting directly to JSP (as in /WEB-INF/jsp/something.jsp) but to an URL (e.g items/search).

It looks like this:

return new ActionForward("items/search/", true);   // Works ok

return new ActionForward("items/search/", false);   // Gives 404

Any ideas what I might be doing wrong?

Upvotes: 0

Views: 1913

Answers (1)

Buhake Sindi
Buhake Sindi

Reputation: 89169

The reason why return new ActionForward("items/search/", false); fails is simple.

By setting redirect to false (which you did in your 2nd parameter of ActionForward), you're effectively asking Struts to check your logical name (in your case items/search/) against the mapping in ActionMapping.

I'm quite sure that in your struts-config.xml there is no <forward> mapping for (items/search/) and thus, a HTTP 404.

Read ActionForward Documentation to understand how it works.

Hope this helps!

Upvotes: 2

Related Questions