TP怎样获取当前页面的完整路径
答案:2 悬赏:30 手机版
解决时间 2021-03-05 23:50
- 提问者网友:wodetian
- 2021-03-05 12:05
TP怎样获取当前页面的完整路径
最佳答案
- 五星知识达人网友:雾月
- 2021-03-05 12:44
第一种:
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
结果:
C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebin
获取当前类的所在工程路径;
如果不加“/”
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
结果:
C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebincomtest
获取当前类的绝对路径;
第二种:
File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
结果:
C:Documents and SettingsAdministratorworkspaceprojectName
获取当前类的所在工程路径;
第三种:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
结果:
file:/C:/Documents%20and%
20Settings/Administrator/workspace/projectName/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径
第四种:
System.out.println(System.getProperty("user.dir"));
结果:
C:Documents and SettingsAdministratorworkspaceprojectName
获取当前工程路径
第五种:
System.out.println( System.getProperty("java.class.path"));
结果:
C:Documents and SettingsAdministratorworkspaceprojectNamebin
File f = new File(this.getClass().getResource("/").getPath());
System.out.println(f);
结果:
C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebin
获取当前类的所在工程路径;
如果不加“/”
File f = new File(this.getClass().getResource("").getPath());
System.out.println(f);
结果:
C:Documents%20and%20SettingsAdministratorworkspaceprojectNamebincomtest
获取当前类的绝对路径;
第二种:
File directory = new File("");//参数为空
String courseFile = directory.getCanonicalPath() ;
System.out.println(courseFile);
结果:
C:Documents and SettingsAdministratorworkspaceprojectName
获取当前类的所在工程路径;
第三种:
URL xmlpath = this.getClass().getClassLoader().getResource("selected.txt");
System.out.println(xmlpath);
结果:
file:/C:/Documents%20and%
20Settings/Administrator/workspace/projectName/bin/selected.txt
获取当前工程src目录下selected.txt文件的路径
第四种:
System.out.println(System.getProperty("user.dir"));
结果:
C:Documents and SettingsAdministratorworkspaceprojectName
获取当前工程路径
第五种:
System.out.println( System.getProperty("java.class.path"));
结果:
C:Documents and SettingsAdministratorworkspaceprojectNamebin
全部回答
- 1楼网友:十年萤火照君眠
- 2021-03-05 12:55
通过图片传值就好了
var img = new image();
img.src = "example.action?data=" + encodeuricomponent(data);
然后在example.action中用get获取到数据
这样不会在页面上生成图片,也不会发生跳转(弱弱说句,这也是xss攻击的一种途径)
当然也可以用ajax提交,原生的比较麻烦,可以考虑借用jquery ajax
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯