kindeditor调用springmvc接口上传文件的代码
解决方法:
@RequestMapping("${trainAndEducate}/uploadKindeditorFile")
public void uploadKindeditorFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
Map<String,Object> result= new HashMap<String, Object>();
// 转型为MultipartHttpRequest:
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
// 获得文件:
MultipartFile file= multipartRequest.getFile("imgFile");
//上传文件的代码省略。。。
result.put("error", 0);
result.put("url", "上传文件的相对路径");
response.setCharacterEncoding("UTF-8");
response.setHeader("X-Frame-Options", "SAMEORIGIN");// 解决IFrame拒绝的问题
PrintWriter writer = response.getWriter();
writer.println(JSON.toJSONString(result));
}