• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

response.sendRedirect() not redirecting

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A page is called and based on the var passed, it determines which site to redirect to browser. I have stripped down the following code to the basic structure. The Page does not get redirected. A blank brower with no error is shown and the address bar still shows the calling page, not the address of the redirected page.

[ December 12, 2005: Message edited by: Adrian Airmil ]
 
Sheriff
Posts: 28325
96
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If InetAddress.getByName throws an exception, then you don't write anything to the response. Which is entirely consistent with the browser displaying a blank screen. You only write to System.out, which is probably a log file in your servlet container somewhere.
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3 questions:

1) Why are you doing this in a JSP rather than a much more appropriate servlet?

2) What does a View Source show is being sent to the browser? If blank, I'd bet your logs have an error message.

3) Hungarian notation? Why? (e.g. sSorry)
[ December 12, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Adrian Airmil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
If InetAddress.getByName throws an exception, then you don't write anything to the response. Which is entirely consistent with the browser displaying a blank screen. You only write to System.out, which is probably a log file in your servlet container somewhere.



The InetAddress.getByName does not throw an exception in this specific case. I threw in some debug lines as folows (before i did the send redirect line) and the site details showed up;

out.println("<br>Name: " + address.getHostName());
out.println("<br>Addr: " + address.getHostAddress());

I should clarify that the page flow is as follows
'options.jsp' calls 'redirect.jsp' which figures out where to redirect based on the option parameter passed and sends the browser to that URL.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My questions remain.
 
Adrian Airmil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
3 questions:

1) Why are you doing this in a JSP rather than a much more appropriate servlet?


We have limited access to working with and setting up servlets.

Originally posted by Bear Bibeault:
2) What does a View Source show is being sent to the browser? If blank, I'd bet your logs have an error message.


Page source is blank as well.

I threw a System.out.print before and after the sendRedirect(). They both get printed, so no exception is being thrown.

Originally posted by Bear Bibeault:
3) Hungarian notation? Why? (e.g. sSorry)



Hungarian? I prefix string vars with an 's' and ints with an 'i' ..etc..
 
Adrian Airmil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:



 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that was Bear's way of noting that he and Paul Clapham "bumped heads" or both posted the same answer at the same time.
It wasn't directed at you.
[ December 12, 2005: Message edited by: Ben Souther ]
 
Adrian Airmil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:


I think that was Bear's way of noting that he and Paul Clapham "bang heads" or both posted the same answer at the same time.
It wasn't directed at you.



Ah i see. Anyway, i feel like banging my head at a wall with this issue.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) This sort of processing is best performed in a servlet. Using a JSP which is meant to render a view for processing is considered a poor practice.

2) Completely blank?

3) Such prefixes, called "Hungarian notation" are usually considered unnecessary in strongly-typed languages such as Java and make your code harder to read.

The next step I would take is to download a means to inspect the headers being sent to the browser. A redirect works by sending a special header in the response which directs the browser to re-issue a request for the redirect URL.

One such tool is Live HTTP Header for Firefox.
[ December 12, 2005: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
I think that was Bear's way of noting that he and Paul Clapham "bumped heads" or both posted the same answer at the same time.
It wasn't directed at you.



Yup! We need a Javaranch-native smilie for this!
 
Adrian Airmil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)Hmmm .. not sure if i can set up a servlet. Our site works with a Content Management system and i can only set up jsp's.

2)Yep completly blank. Nothing in it at all. I have been looking on the console log on the unix box as well. No exceptions/errors being thrown there.

3)Oh, i thought using a prefix made it easier to identify a var on the fly as to its type rather than checking for it. But thanks for the info

OK, i'll look into getting that tool.

Thanks again.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most common error with a redirect is the one cause by an IllegalStateException, when you try writing to the output after the response has been committed.

There are two scenarios
1 - you have written too much content before the redirect, and the buffer has been flushed. It is now too late to redirect, and an IllegalStateException is thrown.
Solutions:
- do as little output as possible before a sendRedirect
- make the page buffer bigger <%@ page buffer="16kb"%> (thats a copout though)

2 - you do the redirect, but execution of the jsp continues and tries to write to the output, or forwards/redirects somewhere else. That would also create an error.
Solution: "return" immediately after calling sendRedirect().

Note that calling sendRedirect() does not stop executing your page.
It merely sends a response to the browser, and keeps running your code.
Thats why you normally want to return from your code after executing a sendRedirect() for forward().
[ December 12, 2005: Message edited by: Stefan Evans ]
 
Have you no shame? Have you no decency? Have you no tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic