web.xml and/or Filters to return welcome-file

Viewed 5275

I have a need to configure my Tomcat WAR for specific functionality, and not sure if it can all be accomplished via web.xml, or if I need to implement 1+ custom Filters, or use some other type of hackery.

My app packages up as myapp.war. So when it's served from a local Tomcat instance, I can access it by going to http://localhost:8080/myapp.

Very simply, I have a welcome-file (myapp.html) that I want served if Tomcat receives the following requests:

  • localhost:8080/myapp
  • localhost:8080/myapp/
  • localhost:8080/myapp/#
  • localhost:8080/myapp/#<blah>

...where <blah> is any string/regex after the pound symbol (#).

So if the user goes to http://localhost:8080/myapp, then serve back myapp.html. If the user goes to http://localhost:8080/myapp/#fjrifjri, then guess what? Serve back myapp.html.

But, if the user goes to, say, http://localhost:8080/myapp/fizz, then I want normal web.xml servlet-mapping logic to kick in, and I want Tomcat to serve back whatever servlet is mapped to /fizz, etc.

Currently my web.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
        version="2.5"
        xmlns="http://java.sun.com/xml/ns/javaee">
    <welcome-file-list>
        <welcome-file>myapp.html</welcome-file>
    </welcome-file-list>
</web-app>

How can I accomplish this?

9 Answers
Related