日期:2014-05-17  浏览次数:20693 次

SSH+JQuery上传图片的例子谁有啊
SSH+JQuery上传图片谁有,不是用form表单提交的
ajaxupload.3.6.js这个是别人推荐的ajax上传控件,但是用不来,谁能讲解下
或者自己做的实例也可以
先谢谢了

------解决方案--------------------
jsp页面:
<form id="addForm" name="addForm" action="${rootUrl}upload/save.do">
 <input type="file" name="image" id="image" />
 <input type="submit" value="上传" />
</form>

Controller:
@RequestMapping(value="/dutyLog/add.do",method=RequestMethod.POST)
public void addGet(HttpServletRequest request,HttpServletResponse response,@ModelAttribute("addModel") AddModel addModel,Model model) throws IOException{
try {
dutyLogManager.add(addModel, request);
writeSuccess2Browers("保存成功", response);
} catch (ManagerException e) {
writeError2Browers("保存失败", response);
}
}
Manager:
@Override
public void add(DutyLogModel addModel,HttpServletRequest request) throws ManagerException {
if(addModel==null)
throw new ManagerException("不能插入空值");
DutyLog log = new DutyLog();
log.setFileName(addModel.getDocfile().getOriginalFilename());
log.setDocfile(addModel.getDocfile());

handleImageFileIn(request,log);
dutyLogDao.save(log);
}
private void handleImageFileIn(HttpServletRequest request,DutyLog log) throws ManagerException {
try {
if (log.getDocfile() != null) {
String fileName = log.getDocfile().getOriginalFilename();
if (FinalString.MAX_FILE_SIZE < log.getDocfile().getSize()) {
throw new ManagerException("文件超过了系统最大约定"+ FinalString.MAX_FILE_SIZE/1048576+ "M");
}
String basePath = request.getSession().getServletContext().getRealPath("/");
handleFileIn(basePath+FinalString.PATH_DUTYLOG_FILE, fileName,log.getDocfile());

log.setInputStream(log.getDocfile().getInputStream());

}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 生成文件
*/
private void handleFileIn(String filePath, String fileName,
MultipartFile mFile) throws IOException {
logger.debug("input2File " + filePath + fileName);
FileTools.input2File(filePath, mFile.getInputStream(), fileName, true);
}