I have a J2EE application with a web service which goes like
http://servername/service?task=getFile&id=25
How can I convert these type of urls to
http://servername/service/getFile/25
http://servername/service/getFile/26
etc?
Please provide your suggestions.
To the point, you thus want to forward the friendly URL to an unfriendly URL (so that you don’t need to change existing request parameter collecting logic of the servlet) and to redirect the unfriendly URL to an friendly URL (so that the friendly URL get reflected in the browser address bar of the client).
The best place for this is a
Filter. To access theHttpServletRequest, just downcastServletRequesttoHttpServletRequest. You can get the query string bygetQueryString()and you can get the pathinfo bygetRequestURI(). Here’s a kickoff example:You can of course also grab the aforementioned
UrlRewriteFilter.