aspose file tools*
The moose likes Struts and the fly likes Tricky Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Tricky" Watch "Tricky" New topic
Author

Tricky

Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi all i was wondering if someone could explain why this code does not redirect the user to the /home action.

I have the following in a jsp page.

<%
boolean redirect = true;

if(redirect) {

%>

<logic:redirect action="/home"/>

<%
}
else {
%>
Not redirecting
<%
}
%>


If i put the <logic:redirect> tag in a jsp without the java scriptlet code it works fine.
Can someone explain why it doesnt work here?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Your code looks good, and I couldn't figure out why it wouldn't work, so I created a simple JSP to test it. Here is my test page:

It works fine. If I set redirect to true, the page is redirected to the specified action. If I set redirect to false, the original page is shown.

Check to see if there are differences between your page and this test page. It may give you a clue as to what you need to change.

One thing to note: The redirect must be the very first output on the page. If you attempt to output anything else (headers, body tag, etc) the redirect will fail.


Merrill
Consultant, Sima Solutions
Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi thank you for your reply.
You answered the question perfectly.
What is actually happening is the page is a tile, and like you said the redirect needs to be the first thing in the page, so i think that other text is being output to the page.

So i guess what i am asking is how do you get the redirect to work if the redirect is in a page that is included in a tiles page?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In that case, you simply can't use a <logic:redirect> in an individual tile. You must solve the problem at the level of the tiles template. Just substitute one page for the other in the template if a certain condition exits.

Another developer had a similar problem recently. It would probably benefit you check out the thread:

http://www.coderanch.com/t/55383/Struts/logic-forward
Patrick McDonogh
Ranch Hand

Joined: Oct 13, 2005
Posts: 89
Hi Merrill

I am sorry for the double post.
I tried to close the last thread as i figured out that it was because the out stream was being flushed.
I thought it may be better to open a new question to avoid confusion.
Sorry and thank you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tricky