File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes redirect if error 404 comes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "redirect if error 404 comes" Watch "redirect if error 404 comes" New topic
Author

redirect if error 404 comes

Gaurav Chhabras
Ranch Hand

Joined: Sep 21, 2005
Posts: 126
HI

now i try to do the following thing -:

i make a jsp page, give a hyperlink there to some page and i have not make that page.This means that it will give the error 404 i.e page not found.

Now in web.xml i have given -:

<web-app>
<error-page>
<error-code>404</error-code>
<location>/pagenotfound.jsp</location>
</error-page>
</web-app>

this means that as user clicks to my link and the page does not exist and then error 404 comes and then it will check in web.xml and rediect to the page defined in <location>/pagenotfound.jsp</location>.

But still my page is giving the error 404 page not found.
my project name is gaurav
i put a.jsp where i give the link, and put the web.xml in web-inf.

Now where should i put "pagenotfound.jsp", in gaurav or in web-inf\

please tell me the proper locations of all the files.


Thanks
Regards
Gaurav
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Gaurav Chhabras:

<web-app>
<error-page>
<error-code>404</error-code>
<location>/pagenotfound.jsp</location>
</error-page>
</web-app>



Is that the entire contents of your web.xml file?
Also it really in a file named "web-inf"?
If so, it should be "WEB-INF".


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gaurav Chhabras
Ranch Hand

Joined: Sep 21, 2005
Posts: 126
Thanks for your response.

It is in WEB-INF and follwing is the full code -:


<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<error-page>
<error-code>404</error-code>
<location>/pagenotfound.jsp</location>
</error-page>

</web-app>


Thanks
Regards
Gaurav
Madhuri Chanda
Greenhorn

Joined: Nov 09, 2005
Posts: 10
The error page should not be in WEB-INF folder.. it has to be in the web folder (along with other jsp files ) where your WEB-INF folder is present.

WEB-INF folder contains .class files, .jar files, .xml files.

And I guess your web.xml file is not complete... I think you have to mention the servlet (<servlet>) and servlet mapping which handles the requests in your web.xml file.

Hope that helps.

Thanks,
Madhuri.
[ December 16, 2005: Message edited by: Madhuri Chanda ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by Madhuri Chanda:
it has to be in the web folder (along with other jsp files ) where your WEB-INF folder is present.


Not correct. Though that is a frequently used location, it's not a "has to".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Madhuri Chanda
Greenhorn

Joined: Nov 09, 2005
Posts: 10
Thanks for the correction Bear.
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
By default, Internet Explorer version 5 ignores server-generated error pages. So, depending on your browser, you may need to go to the Tools menu, select Internet Options, choose the Advanced tab, and make sure �Show friendly HTTP error messages� box is not checked.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: redirect if error 404 comes