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 ]
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.
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;
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 ]
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 ]
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 ]
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad: