文件所在的目录路径,如何找出呢

解决方案 »

  1.   

    <%request.getContextPath() %>/文件夹名
      

  2.   

    你是要绝对路径么
    <%=request.getRealPath("") %>/文件夹名
      

  3.   

    这个问题通过js是不能获取的,问题考虑点转到了request上了,但是普通的HttpServletRequest是不能获取表单那边提交的file,建议LZ使用Spring的MultipartRequest来直接获取file,request.getFile();
    参考:xml
    <bean id="multipartResolver"  
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <!-- 设置上传文件的最大尺寸为1MB -->  
        <property name="maxUploadSize">  
            <value>1048576</value>  
        </property>  
    </bean>public ModelAndView handleRequest(HttpServletRequest request,   
                HttpServletResponse response) throws Exception {   
            // 转型为MultipartHttpRequest:   
            MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;   
            // 获得文件:   
            MultipartFile file = multipartRequest.getFile(" file ");   
            // 获得文件名:   
            String filename = file.getOriginalFilename();   
            // 获得输入流:   
            InputStream input = file.getInputStream();   
            // 写入文件   
      
            // 或者:   
            File source = new File(localfileName.toString());   
            multipartFile.transferTo(source);   
        }    
      

  4.   

    <input type="file" name="file"/>
      

  5.   

    /**
     * 获取file类型的input的全部路径(绝对路径)
     * @param filePathId
     * @return
     */
    function getFilePath(filePathId){  
        //判断浏览器类型  
        var isIE = (document.all) ? true : false;  
        var isIE6 = isIE && (navigator.userAgent.indexOf('MSIE 6.0') != -1);  
        var isIE7 = isIE && (navigator.userAgent.indexOf('MSIE 7.0') != -1);  
        var isIE8 = isIE && (navigator.userAgent.indexOf('MSIE 8.0') != -1);      
        var isIE9 = isIE && (navigator.userAgent.indexOf('MSIE 9.0') != -1);      
        var path = '';  
        if(isIE6 || isIE9)  
        {  
            var file = document.getElementById(filePathId);  
            path = file.value;
        }else if(isIE7 || isIE8)  
        {  
            var file = document.getElementById(filePathId);  
            file.select();  
            path = document.selection.createRange().text;  
            document.selection.empty();  
        }else{  
            try {  
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
            }catch (e) {  
                alert('在地址栏输入about:config,然后修改signed.applets.codebase_principal_support的键值,将值修改为true');  
                return;  
            }  
              
            var fname = document.getElementById(filePathId).value;  
            var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);  
            try {  
                // Back slashes for windows  
                file.initWithPath( fname.replace(/\//g, "\\\\") );  
            }catch(e) {  
                if (e.result!=Components.results.NS_ERROR_FILE_UNRECOGNIZED_PATH) throw e;  
                alert('无法加载文件');  
                return;  
            }  
            path = file.path;  
        }  
        return path;