⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdwebpath.java

📁 j2ee程序。 spring、xml、 实现增加内容选项。
💻 JAVA
字号:
package com.gd.mvc.util;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;


/**
 * 这是公用类,用来获取Web环境的路径,名称等信息.
 */
public class GdWebPath {
    private String webName;
    private String webPhysicsPath;
    
    private String systemName;
    private String systemPath;
    
    /**
     * 该名称返回的是Web名称,如:myApp
     * @return String
     */
    public String getWebName(){
        return this.webName;
    }
    
    /**
     * 该路径指的是Web环境的物理路径,如:D:/eclipse/workspace/myApp
     * @return String
     */
    public String getWebPhysicsPath(){
        return this.webPhysicsPath;
    }
    
    public void getPath() throws IOException {
	    Class cls2 = this.getClass();
	    ProtectionDomain pDomain = cls2.getProtectionDomain();
	    CodeSource cSource = pDomain.getCodeSource();
	    URL loc = cSource.getLocation();//file:/D:/eclipse/workspace/myApp/WEB-INF/classes/com/gd/web/WebPath.class
	    
	    webPhysicsPath = loc.toString().substring(loc.toString().indexOf("/") + 1, loc.toString().indexOf("WEB-INF") - 1);
	    int num = webPhysicsPath.lastIndexOf("/");
	    webName = webPhysicsPath.substring(num + 1, webPhysicsPath.length());
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -