1:spring文件上传不用说了,网上一大堆,这里有个简单的入门例子:http://seaskys.iteye.com/blog/1276680
2:说白了就是IO的转换
@RequestMapping(value = "save")
public EasyUiJsonResult create(@RequestParam(value = "picFileop", required = false) MultipartFile file,@Valid Feasnews feasnews, HttpServletRequest request,HttpServletResponse response)
{
//指定编码,否则会
String encoding = "ISO-8859-1";
byte[] b = null;
String str=null;
try {
b=file.getBytes();
str=new String(b, encoding));
/** 可以把str存入数据库了
* do something
*/
//测试下取出str并显示
FileOutputStream fos = new FileOutputStream(new File("c:/test.png"));
fos.write(str.getBytes(encoding));
fos.flush();
fos.close();
//发送到页面显示
ServletOutputStream sot;
try {
byte b[]=str.getBytes(encoding);
sot = response.getOutputStream();
sot.write(b);
sot.flush();
sot.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return KeeJsonUtils.success("添加成功!");
}
页面接收
<img src="${sot}" title="tt">