• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Page Directive errorPage and isErrorPage

 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this two JSPs,

1st JSP (Hello.jsp):

<%@ page errorPage="errorHandler.jsp" %>
<html>
<body>
<%
if (request.getParameter("name") == null){
throw new RuntimeException("Name Not Specified");
}
%>
Hello, <%= request.getParameter("name") %>
</body>
</html>


2nd JSP (errorHandler.jsp):

<%@ page isErrorPage="true" %>
<html>
<body>
Unable to process your request <br>
Please try again.
</body>
</html>

However, upon running Hello.jsp with "name" parameter equal to null, I always got the message "The page cannot be displayed" in the browser. Why didn't it showed errorHandler.jsp? I know I have trapped the null value.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When u don't enter any value in the TextBox and make a submit, what u get in the server is just an empty string not a null. Try with this code

<%
String inputRequest = request.getParameter("name");
if (inputRequest.equals("")){
throw new RuntimeException("Name Not Specified");
}
%>

You will endup in your errorHandler.jsp page.
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vishnu Prakash,

I tried doing your code but I get still get the same error.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rex,

Are you using IE ? IE does not display the customized error Page. It display its own page.

Thanks
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried doing your code but I get still get the same error.



I gave you the code only after executing it. It worked for me.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Are you using IE ? IE does not display the customized error Page. It display its own page.


Try using the latest version IE. It works fine for me.
 
Anil Sharma
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Richard,

When I put both of these files in same folder.
I do not get any error that you mentioned.
all things are working fine, it is showing the contents the errorHandler.jsp.
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Narendra Dhande, Vishnu Prakash and Anil Kumar Sharma,

I am using Internet Explorer version 6.0 with SP2. As far as I know this is the latest version of MS IE. Nonetheless, if there is a newer version than what I have now, can't it run in IEv6.0? By the way, the error I'm getting was 500 Internal Server Error. Please advise.
 
Jun Liu
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you added the element <error-page> in web.xml?
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>...</location>
</error-page>
 
Vineela Devi
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Do we need to really add the element <error-page>in web.xml to redirect to the error pages if an uncaught exception?I dont think its required.

Its not mentioned anywhere about tht in HFJS.

Also,I have tried an example like this:

index.jsp
<%@ page errorPage = "error.jsp" %>
<html>
<%--
name doent exist as request parameter so request.getParameter("name") returns null
%-->
<%= request.getParameter("name").trim()%>
</html>

error.jsp
<html>
Error Page
</html>

The above example works fine even if I dont have any <error-page> element declared in web.xml

But the whole problem comes when we modify the error.jsp as follows:

error.jsp
<%@ page isErrorPage = "true" %>
<html>
Error Page
</html>

In this case instead of redirecting to error.jsp, Page not found error is displayed.

So I think the problem is somewhere with the isErrorPage attribute.

Anyone please clarify.


Regards,
Vineela
[ November 15, 2005: Message edited by: Vineela Devi ]
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Huh! I still get the same error even if I place an error tag in web.xml.
 
Radhika Jonnalagadda
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Richard,
If it doesn't seem silly, try the code removing "<body> <html> </body> </html>" from the errorHandler.jsp.
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Radhika,
It shouldn't make any difference in having <html> tags.. There are no restrictions for error page.

Richard,
I guess, it is something obvious that you are missing.
we dont need to have error-page declaration in web.xml.
Make sure that you have both files in same directory.
Can you let us know, which web container are you using and which version?
When I copied your jsp pages and ran in was4.0 it worked me straight away! It displays error message to me.
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rizwan,

I am using Tomcat version 5. My 2 jsp's are in the same directory. Both are under my root <chapter10>.

Directory structure:
webapps/chapter10/<this is where the 2 jsps are located>

I know there's nothing wrong with my codes in jsp. Is this because of my IE? I'm using IEv6.0. Will I have to change any of its settings if there is?
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Under internet options in IE, make sure the option to display friendly http errors is not checked.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When setting isErrorPage to true, the status of the http response is set to SC_INTERNAL_SERVER_ERROR.
As somebody said previously, it probably is a problem with the way your browser treats the SC_INTERNAL_SERVER_ERROR.
[ November 27, 2005: Message edited by: Satou kurinosuke ]
 
Richard Rex
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bosun Bello,

Thanks you very much! It did work now! I removed the checked for the friendly error message in IE settings.
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's very helpful to know that the errorPage attribute does not work correctly with the default settings in the most popular browser. This means that in practice some other means of using a custom error page should be employed. Thanks for the tip, Bosun.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joseph Sondow:
It's very helpful to know that the errorPage attribute does not work correctly with the default settings in the most popular browser.


Actually, errorPage works. The problem is isErrorPage. It sets the status code to 500, and IE overrides its behaviour. You'll have to think of something if you're using isErrorPage.
[ November 27, 2005: Message edited by: Satou kurinosuke ]
 
Celso Barreto
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since almost always you can't talk to all your costumer to uncheck this option at IE, insert the following line at the start of you JSP error page:

response.setStatus(javax.servlet.http.HttpServletResponse.HttpServletResponse.SC_OK);

It will change the status code response and make IE think that it is just a normal page. It's ugly but works!
 
Prakash Mani - Attur
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys... disabling friendly error page display in IE solved my one day worry...
 
Prakash Mani - Attur
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sending success code SC_OK for error page is not good idea na.. but your point is valid.. we cant ask every client to disable that option under IE.. is there any other perfect solution???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic