webuploader 接收后台返回中文字符乱码

admin 发布于 2020-03-18T12:40:19 评论(0) 阅读(50)

分类:Java

标签:上传

/**
	 * 附件上传,保存到临时目录下(upload/temp)
	 * @param request
	 * @return 上传状态和上传后的文件路径:成功,success,失败,error
	 */
	@RequestMapping(value="/upload", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")
	@ResponseBody
	public static String upload(HttpServletRequest request,HttpServletResponse response){
		String realPath = request.getSession().getServletContext().getRealPath("/upload");
		String src="",status="success";
		String data="";
		try {
			//上传到临时文件夹
			src= FileHelper.upload(request, realPath, "temp");
			data="{\"src\":\""+src+"\",\"status\":\""+status+"\"}";
			
		} catch (IllegalStateException e) {
			e.printStackTrace();
			status="error";
			data="{\"src\":\""+src+"\",\"status\":\""+status+"\"}";
		} catch (IOException e) {
			e.printStackTrace();
			status="error";
			data="{\"src\":\""+src+"\",\"status\":\""+status+"\"}";
		}
		return data;
	}

 解决办法是在@RequestMapping中设置produces

@RequestMapping(value="/upload", method = RequestMethod.POST, produces = "text/html;charset=UTF-8")