Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

web.xml servlet mappings

Status
Not open for further replies.

MrTom

Programmer
Mar 13, 2001
383
GB
hi!

i'm trying to create a servlet mapping that maps everything to one servlet - but i want it to leave anything alone that already exists.

at the moment i'm using a <url-pattern> of /* but this even takes over things like index.html. i tried using /. but that didn't work either.

so i want the rule that if the file exists then serve it, otherwise run my servlet.

Thanks
 
Sorry, I don't have time to try this with a servlet but hopefully jsp example below will help you get to where you want to go. Any attempt to download a file that does not exist will generate a 404 and the server will redirect to the jsp page defined in location element.

In file myapp/WEB-INF/web.xml, add this descriptor for 404 File Not Found
<error-page>
<error-code>404</error-code>
<location>/myerrorpage.jsp</location>
</error-page>


myErrorPage.jsp -----------------
<%@ page isErrorPage=&quot;true&quot; %>
<html>
<body>
myerrorpage message
</body>
</html>
 
i hadn't thought of using the 404 error. the trouble is that it is not a 404 page.

i wanted to have a very simple form of login where the url mydom.com/mrtom would access a servlet that produced some dynamic content specific to mrtom. but i needed directories that already existed to work normally, eg. mydom.com/images/1.gif

i can't seem to find any documentation on the web.xml file. i can't even see the DTD file in my tomcat4 archive :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top