How do i transform subfolders request to params
I'm using Java serve开发者_如何学运维r, and I need the sub-folders in the request to act like parameters.
example:
myhost/p/a/1
and I need the server to "understand" it like that:
myhost/p?a=1
How can I do that?
Thanks, Koby
1: spring 3 mvc @RequestMapping tag can extract path values from uri
@RequestMapping(value="/owners/{ownerId}", method=RequestMethod.GET)
public String findOwner(@PathVariable String ownerId, Model model) {
Owner owner = ownerService.findOwner(ownerId);
model.addAttribute("owner", owner);
return "displayOwner";
}
2: use UrlRewiter: http://www.tuckey.org/urlrewrite/. This can extract path parameters using regexp.
<rule>
<from>^/image/([A-Za-z0-9-]+).html\??(.*)?$</from>
<to>/image.html?imagecode=$1&$2</to>
</rule>
Create a filter -- in that filter getServletPath()
then parse the path and forward the request to appropriate controller/servlet
Create a filter at say path /files/*
see here,
In this filter add the logic that gets you the whole path after base URL -- i.e. your servlet path see here
You parse this path by splitting using "/"
and then pass the array as the parameter to the servlet that want to use this path. see here for forwarding the request
精彩评论