FileReference.upload 无法正确发布带有附加 unicode 参数的多部分表单
我在一个 Flex 4.0 项目中尝试使用 FileReference.upload() POST 到 Java servlet。我正在发送一些附加参数,例如 POST 中的专辑名称。当字符位于 Latin1 字符集中时,此方法可以正常工作。当我尝试发布日语字符或某些 Unicode 字符时,Java 端无法发送该字符。
FileReference.upload() 忽略内容类型设置并默认使用 multipart/form-data 的内容类型。我不知道在这种情况下默认编码是什么。看来不是UTF-8。
在java端,httpServletRequest.getCharacterEncoding()显示null。该方法是 POST 但我无法确认数据是如何编码的。
所以问题是我似乎被困在使用 FileReference.upload() 因为用户正在选择要上传的文件。我需要发送 Unicode,但无法让 Flash 对其进行正确编码。不确定使用 URLLoader 是否有帮助,或者我是否可以将 FileReference 中的数据获取到 URLLoader (然后丢失进度事件)。
I am in a Flex 4.0 project attempting to POST to a Java servlet using FileReference.upload(). I am sending some additional parameters such as album name in the POST. This works fine when the characters are in the Latin1 character set. When I try to post a Japanese character or some Unicode character, it doesn't come through on the Java side.
FileReference.upload() ignores the content-type setting and uses a Content-Type of multipart/form-data by default. I do not know what the default encoding is in this case. It appears that it is not UTF-8.
On the java side, httpServletRequest.getCharacterEncoding() shows null. The method is POST but I can't confirm how the data is being encoded.
So the problem is that I seem to be stuck using FileReference.upload() because the user is picking the file to upload. I need to send Unicode but I can't get Flash to encode them properly. Not sure if using URLLoader would help or if I can even get the data out of FileReference into URLLoader (and then lose progress events).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需处理server.xml。您需要做的就是在 servlet 中将请求字符集设置为 UTF-8。
There is no need to deal with server.xml. All you need to do is to set requests character set to UTF-8 in the servlet.
所以答案与 Java 端有关,而不是与 Flex 端有关。我必须将 Tomcat server.xml 中的 URIEncoding="UTF-8" 添加到端口 8080 和 8443 的连接器。这就是传递 unicode 值所需的内容。然后我必须确保我的数据源 (SQL Server) 设置为使用 sendStringParametersAsUnicode=true。现在我可以将 unicode 从 Flex 应用程序发布到 Java 应用程序并将其保存在数据库中。
So the answer had to do with the Java side and not the Flex side. I had to add URIEncoding="UTF-8" in my Tomcat server.xml to my connector for ports 8080 and 8443. That is what was needed to pass the unicode values. Then I had to ensure my datasource (SQL Server) was set to use sendStringParametersAsUnicode=true. Now I am able to post unicode from the Flex app to the Java app and save it in the database.