Filename characters encoding in Jsf 2.2 Upload vs. Apache Commons Upload

[亡魂溺海] 提交于 2019-12-02 05:58:05

I reproduced it, WildFly isn't at all considering request request body encoding for multipart/form-data requests. You really have to configure it in server end (like as you would do for GET requests).

Open /standalone/configuration/standalone.xml, peek the following line

<servlet-container name="default">

change it to

<servlet-container name="default" default-encoding="UTF-8">

and restart. This at least worked for me on WildFly 10.0.0. I created issue WFLY-6226 to let it consider request body encoding first so there's no need to edit standalone.xml on that.

In WildFly 8.x (I tested 8.2.1) this unfortunately still won't work as it does not at all consider the above setting. Your best bet is to keep using Apache Commons FileUpload until you can upgrade WildFly.

If you really want to keep native upload, then you could consider to explicitly decode the broken filename to bytes using ISO-8859-1 and then re-encode it using UTF-8.

String fileName = new String(uploadedFile.getFileName().getBytes("ISO-8859-1"), "UTF-8");

This is however brittle and not portable as it would break when deployed to a server where this encoding problem doesn't manifest. So you really need to remember to revert the workaround when upgrading/migrating.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!