1

I'm building a Java web application with HTTP Servlets and I want to route all of the document requests to one Servlet class.

By document request, I mean that I don't want to have requests for images like favicon.ico going to my servlet, which is the case if I just use this mapping.

<servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

What I'm doing is working pretty much like Symfony (the php framework) Controller layer. So I don't know what is the requested URI going to look like, I only know that it's going to follow this pattern: /controller[/method]. So I can't just use /action/* mapping for example.

I'm not looking for any Java MVC framework here since this is a school assignment, so I have to program it myself.

Adam Bečvář
  • 119
  • 1
  • 10
  • And what is wrong with `/action*`? – Elliott Frisch Feb 25 '17 at 15:25
  • The problem is, that I don't know what the calling address is going to look like. Hence my reference to Symfony Controller layer. It's all dynamic. So you can use any combination that follows this pattern: /controller[/method]. But I admit, that I didn't wrote it clearly enough, I'll try to edit it a little. – Adam Bečvář Feb 25 '17 at 15:37

1 Answers1

0

I figured it out, it's more of a workaround, but here is how I did it.

Apparently, I just had to change mapping to / instead of /*

I have all static content in /assets folder so it doesn't interfere with normal requests.

If there's an invalid request like /image.jpg (without /assets), My own code will route this to 404 Controller class, which seems to me like a valid behavior.

Adam Bečvář
  • 119
  • 1
  • 10