public static void main(String[] args){
System.out.println("Java运行时环境版本:\n"+System.getProperty("java.version"));
System.out.println("Java 运行时环境供应商:\n"+System.getProperty("java.vendor"));
System.out.println("Java 供应商的URL:\n"+System.getProperty("java.vendor.url"));
System.out.println("Java安装目录:\n"+System.getProperty("java.home"));
System.out.println("Java 虚拟机规范版本:\n"+System.getProperty("java.vm.specification.version"));
System.out.println("Java 类格式版本号:\n"+System.getProperty("java.class.version"));
System.out.println("Java类路径:\n"+System.getProperty("java.class.path"));
System.out.println("加载库时搜索的路径列表:\n"+System.getProperty("java.library.path"));
System.out.println("默认的临时文件路径:\n"+System.getProperty("java.io.tmpdir"));
System.out.println("要使用的 JIT 编译器的名称:\n"+System.getProperty("java.compiler"));
System.out.println("一个或多个扩展目录的路径:\n"+System.getProperty("java.ext.dirs"));
System.out.println("操作系统的名称:\n"+System.getProperty("os.name"));
System.out.println("操作系统的架构:\n"+System.getProperty("os.arch"));
System.out.println("操作系统的版本:\n"+System.getProperty("os.version"));
System.out.println("文件分隔符(在 UNIX 系统中是“/”):\n"+System.getProperty("file.separator"));
System.out.println("路径分隔符(在 UNIX 系统中是“:”):\n"+System.getProperty("path.separator"));
System.out.println("行分隔符(在 UNIX 系统中是“/n”):\n"+System.getProperty("line.separator"));
System.out.println("用户的账户名称:\n"+System.getProperty("user.name"));
System.out.println("用户的主目录:\n"+System.getProperty("user.home"));
在写java程序时不可避免要获取文件的路径...总结一下,遗漏的随时补上
1.可以在servlet的init方法里
String path = getServletContext().getRealPath("/");
这将获取web项目的全路径
例如 :E:\eclipseM9\workspace\tree\
tree是我web项目的根目录
2.你也可以随时在任意的class里调用
this.getClass().getClassLoader().getResource("/").getPath();
这将获取 到classes目录的全路径
例如 : E:\eclipseM9/workspace/tree/WEB-INF/classes/
这个方法也可以不在web环境里确定路径,比较好用
3.request.getContextPath();
获得web根的上下文环境
如 /tree
tree是我的web项目的root context
/*jsp 取得当前目录的路径
path=request.getRealPath("");
/*得到jbossWEB发布临时目录 warUrl=.../tmp/deploy/tmp14544test-exp.war/
path=C:\jboss-4.0.5.GA\server\default\tmp\deploy\tmp14544test-exp.war\
String path = (String)request.getContextPath();
/*得到项目(test)应用所在的真实的路径 path=/test
String path = request.getRequestURI();
/*得到应用所在的真实的路径 path=/test/admin/admindex.jsp
String savePath=request.getRealPath(request.getServletPath());
/*得到当前文件的磁盘绝对路径
//JAVA 取得当前目录的路径
File file=new File(".");
String path=file.getAbsolutePath();
path=file.getPath();
/*得到jboss运行目录 path=C:\jboss-4.0.5.GA\bin\
4.
web项目中自定义了一个错误页面,例如对404错误进行显示的页面,假设为404.jsp,我们在编写404.jsp页面的时候需要获取当前地址栏的url,也就是确定是哪个页面没有找到。我们会发现调用request.getRequestURL()等方法都是无效的,因为它们返回的都是404.jsp这个页面的路径。
因此我们就要想其他的办法,首先我们在404.jsp中把当前请求的所有http头(getHeaderNames)打印出来,发现没有我们想要的信息;接着我把当前请求对象的所有attributes(getAttributeNames)打印出来就找到了解决的办法了。
String uri = (String)request.getAttribute("javax.servlet.forward.request_uri");