Hi. I am brand new to Java (mostly ASP background) and have had a few Java projects thrown at me and am totally confused...
I need to detect a file not found exception before ever going to a page. This file exists on a different server so I cannot use a relative URL (I think this would eliminate using jsp:forward or jsp:include?) My plan is to use response.sendRedirect in a try/catch statement but I recieve all kinds of errors. What types of (java specific)statements need to be included to set this logic up? I appear to be missing several things. HELP!
While I can't say for sure what's wrong without looking at your code, you should be aware that once you write somethign to a JSP output stream, you can't redirect it. Thus, any redetection code must be done first. This might be the problem that you are experiencing. (Then again, it might not be...)
I'm going to move this to our JSP forum, where I think that you'll find more people focused specifically on JSP issues.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joined: Aug 25, 2004
Joel, Thanks for the reply. I have just started working on this but from what I have found on the web, I have been headed in this direction:
I am totally new to this and may be completely off base. I think I need to declare several things prior to this. I am paging through an old Java text as I write this. My hope is to add this as an include file to all .jsp files in an application.
You shouldn't be doing this from a JSP page at all. Your request should 'hit' a servlet which can perform the file check for you. Because the file exists on another server your best bet would be to try to establish a connection to it using java.net.URLConnection. if that succeeds, you can then forward on to the appropriate JSP page. If not, take whatever action is appropriate. [ August 25, 2004: Message edited by: Bear Bibeault ]
P.S. The redirect approach could never work because all a redirect does is to set up the response headers appropriately so that the when sent back to the browser, the browser initiates another request to the redirect URL. So whether the redirected URL resource exists would not be detected until long after your try/catch block goes out of scope.
Joined: Aug 25, 2004
Back to the drawing board, I guess...
Thanks for the response. I will look into the servlet resolution that you have suggested. [ August 25, 2004: Message edited by: Mike Berna ]