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

解决方案 »

  1.   

    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);
    }
      

  2.   

    AddModel:
    private MultipartFile docfile;
    public MultipartFile getDocfile() {
    return docfile;
    }
    public void setDocfile(MultipartFile docfile) {
    this.docfile = docfile;
    }DutyLog:
    private String fileName;
    private MultipartFile docfile;
    private  InputStream inputStream;
      

  3.   


    这里有个无刷新上传的例子,保存你就自己实现了
    http://yhjhoo.iteye.com/admin/blogs/976087
      

  4.   

    感谢楼上分享,我已经自己做了,但是ajax上传中文图片出现乱码问题有没有好的办法解决
    我是把他截取,然后又重新拼串