Reputation: 1287
I want to be able to have URLs going to servlets like http://host/Servlet/1 rather than http://host/Servlet?ID=1
Any suggestions for how this can be accomplished? Preferably with multiple levels too, so I could do something like http://host/Servlet/1/Files
Thanks
Upvotes: 0
Views: 1453
Reputation: 272
The HttpServletRequest exposes a method, getPathInfo(), which gives you information about the request URL after the servlet path itself. You could map your servlet to /Servlet/* and then get the ID with getPathInfo().
Upvotes: 3
Reputation: 4397
You can do this using Filter. Dispatch incoming URL by some rules and redirect to dispatched URL.
Upvotes: 0
Reputation: 915
One way to solve this could be to have your controller-servlet in front to dispatch to correct servlet in behind depending on the request URI from getRequestURI on the HttpServletRequest.
Upvotes: 0
Reputation: 62603
If you don't have a "must do using Tomcat alone" requirement, I suggest you set up an Apache layer in front of Tomcat where you can have such and other complex URL Rewrites set up.
Upvotes: 0