@PathVariable出现点号"."时导致路径参数截断获取不全的解决办法
问题实例:
@RequestMapping( value = "/file" )
参数声明:@RequestMapping(value = "{filename}", method = RequestMethod.GET)
传入参数:/file/some_file.32HIK345KHJKH.jpg
获取参数:/file/some_file.32HIK345KHJKH
参考链接:
http://stackoverflow.com/questions/3526523/spring-mvc-pathvariable-getting-truncated
http://stackoverflow.com/questions/7027366/spring-3-0-multiple-pathvariables-problem
http://forum.springsource.org/showthread.php?78085-Problems-with-RequestMapping&p=263563#post263563
http://forum.springsource.org/showthread.php?84738-UrlRewrite-PathVariable-multiple-dots-in-filename
Thread: UrlRewrite, @PathVariable multiple dots in filename
参考:http://forum.springsource.org/showthread.php?84738-UrlRewrite-PathVariable-multiple-dots-in-filename
UrlRewrite, @PathVariable multiple dots in filename
I have a "/file" - controller in a Spring REST web application which provides file streams. So a common scenario for a call is:/file/some_file.32HIK345KHJKH.jpg
I use the urlrewrite.xml from the Spring 3 REST example. For the file controller I added a special rule, with regex instead ofwildcards, like follows:
Code:
...
<rule match-type="regex">
<from>^/file/([^/]*)$</from>
<to>/app/file/$1</to>
</rule>
...
The controller handler code for the GET method looks like the following:
Code:
@RequestMapping(value = "{filename}", method = RequestMethod.GET)
public void provideFile(@PathVariable String filename,OutputStream outputStream) throws IOException {
...
// here I do sth. with the filename
...
}
Problem is that the original filename is truncated before last dot. This happens somewhere in between the URL call and the controller handler. So filename only contains: some_file.32HIK345KHJKH instead of some_file.32HIK345KHJKH.jpg
So my question is, what I'm doing wrong and why is the filename truncated at before last dot.
Cheers
Maik
Feb 15th, 2010, 12:14 PM#2
dvestal
Junior Member
Join Date
Jun 2008
Location
Springfield, MO
Posts
21
The @PathVariable resolution will end at the period when using a String variable. You can specify a regex in your @PathVariable declaration though to be able to match your file patterns. I'd have to look at it more closely to determine the actual regex needed, but it shouldn't be difficult.
@PathVariable("{filename:[a-zA-Z0-9\.]+}") String filename
Feb 15th, 2010, 04:52 PM#3
Mammut
Junior Member
Join Date
Feb 2010
Posts
2
@dvestal
Thank you dvestal. You pointed me in the right direction. I did further investigations and found this thread here in den forum:http://forum.springsource.org/showth...563#post263563
So the trick with the regualar expression override did the job.
Cheers
Maik
分享到:
相关推荐
68--[自动点号机].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码68--[自动点号机].zip源码scratch2.0 3.0编程项目源文件源码案例素材源代码68--[自动点号机].zip源码scratch2.0 3.0编程项目源文件源码案例...
C++实现随机点名器 版本v1.0 1.支持文件读入(txt文本文件) 2.支持手动输入 3.不重复点名
本文主要介绍关于mongo数据集合属性存在点号(.)的相关内容,下面话不多说了,来一起看看详细的介绍吧 基本知识点: 1.似乎mongo3.6之前不允许插入带点(.)或美元符号($)的键,但是当我使用mongoimport工具导入...
自动移动管线点点号,引线是点号基点与原来基点,更加直观表示
管线点自动挪点,不是带引线那种,就近找空白位置自动挪动,速度比较慢,但是效果很好,同时增加了自动替换专业代码功能
在Android端新建以点号(.)开头的文件夹或是文件,在PC端挂载此文件夹或是文件
假如有脚本 first.sh: #!/bin/bash #------------------ #@file:first.sh #------------------ echo 'your are in first file' 如何在其它Shell脚本中调用first.sh呢?主要有三种方法:source、...2.点号. #!/bin/b
本文给大家分享JavaScript中的E-mail 地址格式验证,项目要求输入的数据必须包含@符号和点号。代码简单易懂,非常不错,具有参考借鉴价值,需要的朋友参考下吧
在使用eclipse或者MyEclipse工具开发的过程中,您可能会遇到,当您输入点号没有提示,您是不是觉得很郁闷呢,或者还是怀疑这可能是工具的bug呢!... 可是任何问题都有解决的办法,我可个解决大全或许可以帮你。
电子表带点号的展点程序.xls
CASS一键标记高程与点号插件(命令ZD)
CAD管线图文字整饰神器,一键处理,重叠管线点号自动避让处理,又名自动挪点号。采用VB后期绑定技术,几乎可以匹配所有的CAD版本,Windows操作系统32位64位均可。相对第1版,增加了优化次数,标注引线,避让图层增加...
CAD自动编号软件,适合桩位、点号的编制
4. * 要转义的字符包括:1, 点号 . 5. * 2, 中括号 [] 6. * 3, 大括号 {} 7. * 4, 加号 + 8. * 5, 星号 * 9. * 6, 减号 - 10. * 7, 斜杠 \ 11. * 8, 竖线 | 12. * 9, 尖号 ^ 13. * 10, 钱币 $ ...
对话框式选择是否需要引线以及下划线,可设置图层以及偏移量,自动避让管线点号重叠问题,批量自动挪点,可快速整理图面压盖问题。
解决实际问题... 2 作为编程语言的正则表达式... 4 以文件名做类比... 4 以语言做类比... 5 正则表达式的知识框架... 6 对于有部分经验的读者... 6 检索文本文件:Egrep. 6 Egrep元字符... 8 行的起始和...
olebca#连接数据库的软件管线人员必用