【发布时间】:2025-09-19 04:15:01
【问题描述】:
当我在 GWT 的 HttpServletRequest 中调用 request.getParameter( "filename" ) 时遇到了问题。这是我如何编码 URL 的代码:
String sFile = URL.encodeQueryString( "°^!§$%()=`´' glassfish +~#'@€-_²³.pdf" );
String sURL = GWT.getModuleBaseURL() + "filehttpservice" // name of the httpservlet
+ "?filename=" + sFile; // the name of the file to download
Window.open( sURL, "_blank", sFeatures ); // sFeatures are some window-settings
所以我想下载一个名称中包含一些特殊字符的文件。 URL 编码的名称是:
%C2%B0%5E!%C2%A7%24%25()%3D%60%C2%B4'%20glassfish%20%2B~%23'%40%E2%82%AC-_%C2%B2%C2%B3.pdf
这是正确的,因为我可以用这个名字直接在浏览器中调用文件。
因此,当请求到达 HttpServlet 的 get-Method 时,我想使用以下代码从其参数中提取文件名:
request.setCharacterEncoding( "UTF-8" );
String sFilename = request.getParameter( "filename" );
但是收到的文件名是:
°^!§$%()=`´' glassfish +~#'@â¬-_²³.pdf
这是完全错误的。
我已经搜索了很长时间并尝试了多种解决方案,但没有任何改变。有人知道我怎样才能收到正确的文件名吗?
【问题讨论】: