Results 1 to 6 of 6

Thread: custom 404 page

  1. #1
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default custom 404 page

    I use the tomcat-server for my java server pages.

    I wanna set a "file not found" page for my server.
    Now I get the by tomcat-used file:
    Java Code:
    <html><head><title>Apache Tomcat/7.0.4 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /asdfs</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/asdfs</u></p><p><b>description</b> <u>The requested resource (/asdfs) is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.4</h3></body></html>
    I allready tried to change a error-code with:
    Java Code:
    	<error-page> 
    		<error-code>404</error-code> 
    		<location>/error404.jsp</location> 
    	</error-page>
    In my directory's WEB-INF/web.xml and in the conf/web.xml.
    But none of them work.

    Can someone help me to set a 404 errorpage for my server?

    Thanks,
    Dennis

  2. #2
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    So you declared error page in the web.xml for HTTP error code type 404,
    and it look fine.

    But instead of yours error404.jsp you get Tomcat's error page.

    Please paste here error404.jsp and before that check a path of this file.

  3. #3
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    I've allready searched for the Tomcat's error page, but I can't find it.
    There are many "error.jsp"/"error404.jsp"/"404.jsp" pages, but none of them have the same source as the receiving error404 page.

  4. #4
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    For a better explanation:

    My "error404.jsp" is located at: "$CATALINA_HOME/webapps/ROOT".
    My "web.xml" is located at "$CATALINA_HOME/webapps/ROOT/WEB-INF".

  5. #5
    FON
    FON is offline Senior Member
    Join Date
    Dec 2009
    Location
    Belgrade, Serbia
    Posts
    364
    Rep Power
    5

    Default

    Create error page in your own project and place it in:

    ...MyWebProject\WebContent\notFoundError.jsp

    In:
    ...MyWebProject\WebContent\WEB-INF\web.xml
    place this tag after welcome file list:

    Java Code:
      <error-page>
         <error-code>404</error-code>
         <location>/notFoundError.jsp</location>
    </error-page>
    Restart Tomcat.

    Hit some non existing URL (don't use IE as browser):
    http://localhost:8080/MyWebProject/aaa.html

    you will get your error page.

  6. #6
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    It doesn't work.

    I use the browser "google chrome".
    And I get the google-chrome errorpage.

    And why al these files must be put in the directory "MyWebProject/WebContent"
    but I must go to the url "MyWebProject", why not "MyWebProject/WebContent"?

    xml-page:
    Java Code:
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
    
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    
    	<error-page>
    		<error-code>404</error-code>
    		<location>/notFoundError.jsp</location>
    	</error-page>
    </web-app>
    ----------EDIT----------

    It works at Firefox!
    But I don't understand why it doesn't work in other browsers.
    because the server only return some bytes from the server.
    If the asked page exist it should return the bytes from that file.
    if the asked page doesn't exist it should return the bytes from the error file.

    Am I right?
    Last edited by Dennis; 11-09-2010 at 02:35 PM.

Similar Threads

  1. Go back to previous page using session in JSP page
    By gopikarikati009 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-23-2011, 10:30 AM
  2. Page to page navigation
    By leovach in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-17-2010, 09:29 AM
  3. Replies: 0
    Last Post: 03-02-2010, 08:28 AM
  4. setting the view to a jsp page from a self refeshing page
    By deepal_205 in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 08-15-2008, 04:41 PM
  5. warning that page has expired and i need to refresh the page again
    By 82rathi.angara in forum JavaServer Pages (JSP) and JSTL
    Replies: 5
    Last Post: 07-15-2008, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •