views:

282

answers:

2

Hi

i have a condition where an URL is manipulated or changed wantedly. i have to catch the error and move to error page. but the error page is never called.

I am using response.sendRedirect("MyURL"); in the jsp page. If the URL is correct its working fine.

If i manipulate the URL and use the command it shows HTTP 404 error in the same page but not calling the error page

here is my code.

one.jsp  
---------  
<%@ page errorPage="exceptionHandler.jsp" %>  
<%

String webBrowserURL="http://URL"  

response.sendRedirect(webBrowserURL);  

%>  


exceptionHandler.jsp  
------------------------  

<%@ page isErrorPage="true" %>  
<% String root = request.getContextPath(); %>  

                <%  
                         //get the correct url form the database and send it to the page  
                %>  


<jsp:forward page="one.jsp" />  

Help me

+1  A: 

So if the URL is correct and the redirect works fine, then why would you expect it to work with an incorrect URL?

Check that you're using the proper URL and ensure that you're not printing anything on your JSP, like out.println("something") or that you don't have any HTML code before calling the redirect.

Lirik
A: 

You shouldn't be doing this inside a JSP file. It's often already too late to change the response then. If you check the server logs, then the chance is big that you see IllegalStateException: response already committed spreading over the logs.

The best place to do this kind of stuff is a Filter. Keep JSP development rule #1 in mind: raw Java code belongs in Java classes, not in JSP files. You're developing code, not prototyping code.

BalusC