tomcat当前的绝对路径

tomcat当前的绝对路径,第1张

//获取到ServletContext就可以了

ServletContext context=ServletActionContextgetServletContext();

String path=contextgetRealPath("/");

int pos=pathlastIndexOf("\\", pathlength()-2);

pos=pathlastIndexOf("\\", pos-1);

path=pathsubstring(0, pos+1);

Systemoutprintln(path);

在servlet的init方法里,调用:

public void init(ServletConfig config) throws ServletException{

superinit(config);

String appPath = configgetServletContext()getRealPath(""); // tomcat的物理路径

}

以上就是关于tomcat当前的绝对路径全部的内容,包括:tomcat当前的绝对路径、怎么用getrealpath 获取tomcat的路径、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9796278.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-02
下一篇 2023-05-02

发表评论

登录后才能评论

评论列表(0条)

保存