自己动手写struts笔记1
2016-03-12 20:53
330 查看
package com.gd.mvc.util;
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
/**
* 这是一个公共类 用于获取web环境的路径 名称等信息
* @author lx
*
*/
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
*/
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);
System.out.println("webPhysicsPath "+webPhysicsPath);
int num=webPhysicsPath.lastIndexOf("/");
webName=webPhysicsPath.substring(num+1,webPhysicsPath.length());
System.out.println("webName: "+webName);
}
// public static void main(String args[]) throws IOException{
// GdWebPath gdw=new GdWebPath();
// gdw.getPath();
// }
}
import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
/**
* 这是一个公共类 用于获取web环境的路径 名称等信息
* @author lx
*
*/
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
*/
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);
System.out.println("webPhysicsPath "+webPhysicsPath);
int num=webPhysicsPath.lastIndexOf("/");
webName=webPhysicsPath.substring(num+1,webPhysicsPath.length());
System.out.println("webName: "+webName);
}
// public static void main(String args[]) throws IOException{
// GdWebPath gdw=new GdWebPath();
// gdw.getPath();
// }
}
相关文章推荐
- Rxjava、retrofit初探
- Java把长整型时间转成字符串日期
- 【JAVA集合】LinkedList
- Spring技术内幕——深入解析Spring架构与设计原理(一)IOC实现原理
- 嵌套类的语法
- java初学之学习 变量数位,数据类型等
- Java敏捷开发
- String 比较
- Java内存管理:深入Java内存区域
- Java类加载与实例化过程
- Java小知识
- SSH学习之一,struts框架入门
- Java NIO Scatter / Gather
- 40个Java多线程问题总结
- 20145326《Java程序设计》第二周学习总结
- Java中的解析Xml
- Java多线程回顾1:线程的概念及创建
- Java集合源码学习笔记(二)ArrayList分析
- BIO | NIO | AIO (Java版)
- java入门学习(15)—多线程