上传文件,想把上传的文件放在项目根目录下面的upload文件夹下
在jsp中       String path = request.getContextPath();
       String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; String url = basePath+"upLoad";
    File file = new File(url);
    if(!file.exists()){
    file.mkdir();
    }upLoad文件夹无法正确创建,请帮忙!!!

解决方案 »

  1.   

    我觉得你应该把url输出看看,是不是正常的创建路径
      

  2.   

    url输出的是:http://localhost:8080/MBS/upLoad
      

  3.   

    url输出的是:http://localhost:8080/MBS/upLoad
      

  4.   

    你这是在jsp页面写的吧?直接把url改成String url = "upload";即可
      

  5.   

    直接写"项目路径+upload";
    比如:"C:\Documents and Settings\Administrator\Workspaces\MyEclipse\MBS\upload";
      

  6.   

    request.getSession().getServletContext().getRealPath("/")
    再加上upload
      

  7.   

    我用的是tomcat,直接把url改成String url = "upload"; upLoad文件夹就建在了 tomcat/bin 下面,不是建在项目根目录下面啊,请帮忙急!!!
      

  8.   

    String filePath = request.getSession().getServletContext()
    .getRealPath("/")
    + "upload";// 上传文件保存的目录
      

  9.   

    这个创建的upload是放在项目发布的地方,一般是在\Tomcat 6.0\webapps下面,根本不在项目根目录下
      

  10.   

    直接写"项目路径+upload",
    比如:"C:\Documents and Settings\Administrator\Workspaces\MyEclipse\MBS\upload";