⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smartupload组件上传的中文问题.txt

📁 java在SmartUpload组件上传的中文问题的一个解决方案
💻 TXT
字号:
很简单的问题,查了半天,不是推荐别的就是什么什么,试验了N个其他组件,还是不行,表单传递的UTF-8汉字有问题,中文文件上传也有问题,郁闷了。
结果不小心就解决了:new String(str.getBytes(),"UTF-8")
不说了,下面做个记录。
 
提交表单
<form action="upload.jsp" method="post" enctype="multipart/form-data">
  <table>
    <tr><td><input type="text" name="newFile"></td></tr>
    <tr><td><input type="file" name="file"><input type="submit" value="upload"></td></tr>
  </table>
</form>
 
处理页面
  com.jspsmart.upload.SmartUpload smartUpload = new com.jspsmart.upload.SmartUpload();
  smartUpload.initialize(pageContext);
  smartUpload.service(request, response);
  smartUpload.upload();
  com.jspsmart.upload.File file = smartUpload.getFiles().getFile(0);
  //取中文文件名
  String fileName = new String(file.getFileName().getBytes(),"UTF-8");
  //取中文表单参数
  String newFileName = new String(smartUpload.getRequest().getParameter("newFile").getBytes,"UTF-8");
  //改名上传
  file.saveAs("upload/" + newFileName,smartUpload.SAVE_VIRTUAL);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -