Question

I'm working in Eclipse+tomcat. My custom made static error page is not showing up in tomcat when i click on url for non-existing pages. generated-error.html has a simple img src="404_man.jpg" tag. But I keep getting the error page shown on the pic.

enter image description here

My servlet version is 3.0 if i view it from manifest.mf. I think it's the right document to look for Servlet version?

enter image description here Pls don't leave me hanging...

Was it helpful?

Solution 3

You should add the error code or exception-type tags in web.xml for particular error...

<error-page>
    <error-code>404</error-code>
    <location>/error.jsp</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/error.jsp</location>
</error-page>

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp</location>
</error-page>

OTHER TIPS

Before servlet version 3.0 you'll have to specify an error code using the error-code tag. It is not required since 3.0. Check if you really use this version. Your web-app tag should look like:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0"> 

It seems Internet Explorer issue. Try disabling the option - "Show friendly HTTP error messages" in "Advanced" tab of "Internet Options".

In your error page you have to add isErrorPage="true".

If you want static error page, Than you need to do:

1.include similar to below given example in web.xml file:

<error-page>
    <error-code>404</error-code>
    <location>/error-404.jsp</location>
</error-page>
  1. in static error file (i.e. error-404.jsp) add "isErrorPage="true" in page-dependent attributes. See example:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" isErrorPage="true"%>
  1. Try firefox or chrome. Many times it worked for me.

Interesting, I added <exception-type>java.lang.Exception</exception-type>, deployed tomcat, deleted exception type back, restarted tomcat with no <error-code> line, and it worked. still no idea what was the reason behind the problem that cost me one whole day.

EDIT: Restart again, and now it doesn't work...

I restarted again, but still doesn't work, is this a cache problem? it's definitely something that i have no idea of...

Try from another browser, instead of internal eclipse browser. And make sure error.jsp is on same level as web-inf folder.

For all of you looking for a simple straight forward solution

Please do the following .

1) try running in firefox

2) try running in chrome

root cause : The root cause is internet explorer , since eclipse takes

IE as default browser you keep getting http error . please do as I said

It will work for you . if you like my solution do comment on it : )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top