发布于 2016-08-18 04:47:10 | 118 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的JSP学习教程,程序狗速度看过来!

JSP JAVA公司的WEB开发编程语言

JSP全名为Java Server Pages - java服务器页面是由Sun Microsystems公司倡导、许多公司参与一起建立的一种动态网页技术标准。JSP技术有点类似ASP技术,它是在传统的网页HTML(标准通用标记语言的子集)文件(*.htm,*.html)中插入Java程序段(Scriptlet)和JSP标记(tag),从而形成JSP文件,后缀名为(*.jsp)。


这篇文章主要介绍了jsp中获取当前目录的方法,实例分析了JSP获取当前路径的方法,并对相关目录操作函数进行了总结归纳,是非常实用的技巧,需要的朋友可以参考下

本文实例讲述了jsp中获取当前目录的实现方法,分享给大家供大家参考。具体实现方法如下:

1、利用System.getProperty()函数获取当前路径:

System.out.println(System.getProperty("user.dir"));//user.dir指定了当前的路径

2、使用File提供的函数获取当前路径:
File directory = new File("");//设定为当前文件夹

try{

System.out.println(directory.getCanonicalPath());//获取标准的路径

System.out.println(directory.getAbsolutePath());//获取绝对路径

}catch(Exceptin e){}

File.getCanonicalPath()和File.getAbsolutePath()大约只是对于new File(".")和new File("..")两种路径有所区别。

# 对于getCanonicalPath()函数,“."就表示当前的文件夹,而”..“则表示当前文件夹的上一级文件夹
# 对于getAbsolutePath()函数,则不管”.”、“..”,返回当前的路径加上你在new File()时设定的路径
# 至于getPath()函数,得到的只是你在new File()时设定的路径

比如当前的路径为 C:test :

File directory = new File("abc");

directory.getCanonicalPath(); //得到的是C:testabc

directory.getAbsolutePath(); //得到的是C:testabc

direcotry.getPath(); //得到的是abc

File directory = new File(".");

directory.getCanonicalPath(); //得到的是C:test

directory.getAbsolutePath(); //得到的是C:test.

direcotry.getPath(); //得到的是.

File directory = new File("..");

directory.getCanonicalPath(); //得到的是C:

directory.getAbsolutePath(); //得到的是C:test..

direcotry.getPath(); //得到的是..

获取 JAVA 程序当前的工作目录

File file = new File("t.tmp");

String fullpath = file.getAbsolutePath();

① request.getRealPath:

方法:request.getRealPath("/")
得到的路径:C:Program FilesApache Software FoundationTomcat 5.5webappsstrutsTest

方法:request.getRealPath(".")
得到的路径:C:Program FilesApache Software FoundationTomcat 5.5webappsstrutsTest.

方法:request.getRealPath("")
得到的路径:C:Program FilesApache Software FoundationTomcat 5.5webappsstrutsTest

方法:request.getRealPath("web.xml")
得到的路径:C:Program FilesApache Software FoundationTomcat 5.5webappsstrutsTestweb.xml

② request.getParameter("");
    ActionForm.getMyFile();
方法:String filepath = request.getParameter("myFile");
得到的路径:D:VSS安装目录users.txt

方法:String filepath = ActionForm.getMyFile();
得到的路径:D:VSS安装目录users.txt

希望本文所述对大家的jsp程序设计有所帮助。



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务