This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes action forward problem : when Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "action forward problem : when "Failure"" Watch "action forward problem : when "Failure"" New topic
Author

action forward problem : when "Failure"

azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
When an error is found in validate and the forwarded to failure mapping I find that redirection does not occur. I have specified redirect="true" in struts-config.
Because of this, the layout is in disorder since I use css, which is a big problem. I know the css problem may be solved if i use absolute url of the css resource. But,i cant do that for several reasons. and even if i can do it somehow, i am still curious why this problem occurs in the first place. Should it not redirect to the page when redirect attribute is true?

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
There's one sure-fire way to tell whether a redirect occurred or not. Check the URL. If it ends with xxxForm.jsp, then a redirect did occur. If it ends with xxxPost.do, then it didn't.

If you're having problems with the JSP finding th .css file, I'd suggest using the <html:base/> tag. This tag makes it so that all references in the page are relative to the location of the current JSP page.
[ August 07, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
it ends with xxPost.do, so its not a redirect.

Any idea why redirect does not happen?
[ August 07, 2006: Message edited by: azhar bharat ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Do you have a global forward with the name "Failure"?
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
yes, ofcourse.
see the code in the first post.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
The code in your first post shows me a local forward. I'm asking if you have a global forward of the same name, particularly one that does not redirect.

A global forward looks like this:

<global-forwards>
<forward name="foo" path="/foo.jsp"/>
</global-forwards>
[ August 08, 2006: Message edited by: Merrill Higginson ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What is the css issue? Here is the code I have in my JSP files for loading the css file.

<link rel="stylesheet" type="text/css" href="<html:rewrite page='/css/style.css'/>" />

And about the redirect problem...Am I misunderstanding something? When validation fails the input attribute is used, not your Failure forward. Why would you want to redirect on the validation failure case?

- Brent
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
Sorry, i missed the "global" in your post.

I do not have any global forwards for "failure".

for sake of clarity, i am posting my global-forwards
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
Hi
I have not sorted out this problem yet.
Can anyone help?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I tried. When validation fails the path specified by the input attribute is used, not your "Failure" forward (unless I missed some changes in Struts 1.2). I am still not sure why you would want to redirect on a validation failure.

- Brent
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
I got confused a bit.

Here is the problem again.

when i use the "failure" mapping to redirect from Action, it works fine, it redirects and the page is proper.

But when there is an error in ActionForm the control is NOT REDIRECTED, ONLY TRANSFERRED to the page in the "input" attribute. So, i can see the page, but the address bar shows xxPost.do which is the Action mapping, which means that it is not redirected.

How do i redirect to the page instead or a forward when an error occurs in the ActionForm?
[ August 23, 2006: Message edited by: azhar bharat ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I was looking into this a little more. The documentation and source that I looked at was for Struts 1.1, so you might want to double check your version of Struts. The controller element in your struts-config file has an attribute named inputForward. The default value is false. It looks like if you set this value to true, then Struts (the code in RequestProcessor) will treat the value in the input as the name of a forward. This may work for you, though I am pretty sure you would have to apply this change to all of your action mappings.

Add this entry to your struts-config file:


Change your mapping to something like this (I just changed the input attribute):


- Brent
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
Originally posted by Brent Sterling:
I was looking into this a little more. The documentation and source that I looked at was for Struts 1.1, so you might want to double check your version of Struts. The controller element in your struts-config file has an attribute named inputForward. The default value is false. It looks like if you set this value to true, then Struts (the code in RequestProcessor) will treat the value in the input as the name of a forward. This may work for you, though I am pretty sure you would have to apply this change to all of your action mappings.

Add this entry to your struts-config file:


Change your mapping to something like this (I just changed the input attribute):


- Brent


thanks, it redirects now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: action forward problem : when "Failure"
 
Similar Threads
Struts-config.xml
Actionforward Problem
newbie problem - populating Action form
Struts Cancel Button submits the form
Refresh Problem : same action gets called