ServletActionContext.getServletContext().getRealPath()方法调用报错

ServletActionContext.getServletContext().getRealPath()方法调用报错,第1张

我以前也用这个方法获取服务器端路径运行时也报错···因为我用的公司产品框架···我感觉这个是单独servlet的时候可以用···
你是不是要获取服务器端的路径,我给你提供下我写的方法你可以参考下:
/
获取服务器端的webapps路径
@return
/
public String findServerPath(){
String classPath = thisgetClass()getClassLoader()getResource("/")getPath();
try {
classPath =URLDecoderdecode(classPath, "gb2312");
} catch (UnsupportedEncodingException e) {
eprintStackTrace();
}
String[] strPath = classPathsplit("/");
String path = "";
for(int i = 0;i < strPathlength ; i++){
if(i > 0 && i <= 3){
path = path + strPath[i]+"/";
}
}
return path;
}


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

原文地址: https://outofmemory.cn/zz/10860555.html

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

发表评论

登录后才能评论

评论列表(0条)

保存