• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tricky

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

https://coderanch.com/t/55383/Struts/logic-forward
 
Patrick McDonogh
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic