zoukankan      html  css  js  c++  java
  • com.classpath.www

    package com.classpath.www;
    
    import java.io.File;
    import java.net.URL;
    
    import javax.servlet.ServletContext;
    import javax.servlet.http.HttpServletRequest;
    
    /**
     * 路径获取类
     * */
    public class WebPath {
        /**
         * 获取项目根目录的绝对路径
         * 
         * @return 如:F:TongJianpengJ2EEUtil
         * */
        public static String getAbsolutePathWithProject() {
            return System.getProperty("user.dir");
        }
    
        /**
         * 获取项目所在盘符
         * */
        public static String getDriverPathWithProject() {
            return new File("/").getAbsolutePath();
        }
    
        /**
         * 获取项目根目录的绝对路径
         * 
         * @return 项目根目.例如<br/>
         *         F:	omcatwebappsJ2EEUtil
         * */
        public static String getAbsolutePathWithWebProject(
                HttpServletRequest request) {
            return request.getSession().getServletContext().getRealPath("/");
        }
    
        /**
         * 获取项目根目录下的指定目录的绝对路径
         * 
         * @param 项目根目下的指定目录
         *            .例如:/login/
         * @return 项目根目下的指定目录.例如:<br/>
         *         F:	omcatwebappsJ2EEUtillogin
         * */
        public static String getAbsolutePathWithWebProject(
                HttpServletRequest request, String path) {
            return request.getSession().getServletContext().getRealPath(path);
        }
    
        /**
         * 获取项目根目录的绝对路径
         * 
         * @return 项目根目.例如<br/>
         *         F:	omcatwebappsJ2EEUtil
         * */
        public static String getAbsolutePathWithWebProject(ServletContext context) {
            return context.getRealPath("/");
        }
    
        /**
         * 获取项目根目录下的指定目录的绝对路径
         * 
         * @param 项目根目下的指定目录
         *            .例如:/login/
         * @return 项目根目下的指定目录.例如:<br/>
         *         F:	omcatwebappsJ2EEUtillogin
         * */
        public static String getAbsolutePathWithWebProject(ServletContext context,
                String path) {
            return context.getRealPath(path);
        }
    
        /**
         * 获取项目classpath目录的绝对路径
         * 
         * @return classes目录的绝对路径<br/>
         *         file:/F:/tomcat/webapps/J2EEUtil/WEB-INF/classes/
         * */
        public static URL getAbsolutePathWithClass() {
            return WebPath.class.getResource("/");
        }
    
        /**
         * 获取项目classPath目录下的指定目录的绝对路径
         * 
         * @param path
         *            classes目录下的指定目录.比如:/com/
         * @return file:/F:/tomcat/webapps/J2EEUtil/WEB-INF/classes/com/
         * */
        public static URL getAbsolutePathWithClass(String path) {
            return WebPath.class.getResource(path);
        }
    
        /**
         * 获取指定类文件的所在目录的绝对路径
         * 
         * @param clazz
         *            类
         * @return 类文件的绝对路径.例如:<br/>
         *         包com.Aries.Util.Web下的Main.java类.<br/>
         *         路径为:file:/
         *         F:/tomcat/webapps/J2EEUtil/WEB-INF/classes/com/Aries/Util/Web/
         * */
        public static URL getAbsolutePathWithClass(Class clazz) {
            return clazz.getResource("");
        }
    }
  • 相关阅读:
    flash 自定义右键功能
    本地和VMware虚拟主机之间的网络访问
    java: org.luaj.vm2.LuaError:XXX module not found lua脚本初始化出错
    火狐 提示“此连接是不受信任的” 可能是因为开启了其它抓包代理软件导致的
    批量导入数据库
    引用Interop.SQLDMO.dll后的注意事项。
    c# Invoke和BeginInvoke 区别
    闭包的7种形式
    C#使用ICSharpCode.SharpZipLib压缩后进行web批量下载文件
    C# Socket编程笔记
  • 原文地址:https://www.cnblogs.com/MarchThree/p/3655489.html
Copyright © 2011-2022 走看看