本帖最后由 aa474378750 于 2011-12-07 21:47:42 编辑

解决方案 »

  1.   

            String path = ServletActionContext.getRequest().getRealPath("/upload");这句话改成 String path = "../upload";应该可以的吧
      

  2.   

    也不行啊,改成../upload直接报错。
      

  3.   


    public void upload(){
      
    try {

    //创建文件流,用来读写
    //1. 创建写入对象
    FileOutputStream out = new FileOutputStream(new File(ServletActionContext.getServletContext().
    getRealPath("/")+"/upload/"+getImageFileName()));

    System.out.println("--->:"+getImage());

    //2. 创建读取对象
    FileInputStream in = new FileInputStream(getImage());

    //3.一边读取一边写入
    byte [] data = new byte[1024];//

    int len = 0;

    while((len=in.read(data))>0){//read()方法,用来将数据读取到数组中,返回读取的个数
    out.write(data,0,len);
    }

    out.close();
    in.close();
    } catch (Exception e) {
    e.printStackTrace();
    }

    System.out.println("哈哈,上传cheng共!");
    }