我使用的是 Java 服务器,我需要请求中的子文件夹来充当参数。
示例:
myhost/p/a/1
我需要服务器像这样“理解”它:
myhost/p?a=1
我怎样才能做到这一点?
谢谢, 科比
最佳答案
1:spring 3 mvc @RequestMapping标签可以从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:使用UrlRewiter:http://www.tuckey.org/urlrewrite/ 。这可以使用正则表达式提取路径参数。
<rule>
<from>^/image/([A-Za-z0-9-]+).html\??(.*)?$</from>
<to>/image.html?imagecode=$1&$2</to>
</rule>
关于java - 如何将子文件夹请求转换为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4544951/