我在spring mvc中有文件上传它在firefox中工作正常但在IE9
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.
这就是我的形式:
这就是我的控制器:
@RequestMapping(value = "/CIMtrek_Regional_WhseFormAddSave", method = RequestMethod.POST)
public ModelAndView CIMtrek_Regional_Whse(
@RequestParam("CIMtrek_xmlData") String CIMtrek_xmlData,
@RequestParam("CIMtrek_formName") String CIMtrek_formName,@RequestParam("fileUPload") MultipartFile uploadFile,HttpServletRequest request) {
UtilService fileUploadService = new UtilService();
if(!uploadFile.isEmpty()) {
fileUploadService.saveFile(uploadFile, request.getRealPath(""));
}
ViewContent vc = new ViewContent();
String HTML = vc.getContent(CIMtrek_xmlData, CIMtrek_formName);
List<String> ls = new ArrayList<String>();
ls.add(HTML);
logger.info("Welcome CIMtrek_Regional_Whse Add!");
return new ModelAndView("form", "list", ls);
}
文件保存方法:
public void saveFile(MultipartFile uploadItem, String requestPath) {
File dir;
File file;
try {
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if (uploadItem.getSize() > 0) {
inputStream = uploadItem.getInputStream();
fileName = requestPath + "\\resources\\Attachment\\";
dir = new File(fileName);
if (!dir.exists()) {
dir.mkdirs();
}
fileName += uploadItem.getOriginalFilename();
file = new File(fileName);
if (!file.exists()) {
file.createNewFile();
}
outputStream = new FileOutputStream(file);
int readBytes = 0;
byte[] buffer = new byte[10000];
while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.flush();
outputStream.close();
inputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
请帮我解决这个问题。提交表单时,我将文件保存到指定位置。
此致