webuploader 接收後臺返回中文字符亂碼

/**
	 * 附件上傳,保存到臨時目錄下(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")

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章