我用fileupload上传图片,我自己在自己机器上可以上传,但别人通过网站访问就上传不了。
不知道怎么回事?
没用什么框架,就是jsp

解决方案 »

  1.   

    FileItemFactory factory = new DiskFileItemFactory();
    FileUpload fu = new FileUpload(factory);fu.setFileSizeMax(512000);
    RequestContext rc = new ServletRequestContext(request);List<FileItem> list = null;
    try
    {
    //解析上传的文件
    list = fu.parseRequest(rc);
    }
    catch(FileUploadBase.FileSizeLimitExceededException e)
    {
    out.println("上传的文件过大!!!");
    return;
    }//得到userImg的绝对路径
    String rootPath = request.getRealPath("/userImg");
    String virPath = "userImg/";File file = new File(item.getName());
         File save = new File(rootPath, file.getName());
         String type = item.getName().substring(item.getName().lastIndexOf("."));
         item.write(save);
         File temp = new File(rootPath, name + "logo" + type);
         save.renameTo(temp);
         String path = (virPath + name + "logo" + type).replaceAll("\\\\", "\\|");
         stmt.executeUpdate("update shop set logo = '" + path + "' where id = " + id);