如何在linux搭建web服务器

如何在linux搭建web服务器,第1张

web服务器常见的是apache和nginx。apache嫌麻烦就直接用软件管理工具(centos跟小红帽用yum,ubuntu用apt-get)安装,也可以到官网下载httpd-2.4.25.tar.gz,解压并编译安装,nginx同理

java获取根路径有两种方式:

1),在servlet可以用一下方法取得:

request.getRealPath(“/”) 例如:filepach = request.getRealPath(“/”) ”//upload//”

2),不从jsp,或servlet中获取,只从普通java类中获取:

String path =

getClass().getProtectionDomain().getCodeSource().getLocation().getPath()

SAXReader() saxReader = new SAXReader()

if(path.indexOf(“WEB-INF”)>0){

path = path.substring(0,path.indexOf(“/WEB-INF/classes”) 16)

// ‘/WEB-INF/classes’为16位

document = saxReader.read(path filename)

}else{

document = saxReader.read(getClass().getResourceAsStream(filename))

}

weblogic tomcat 下都有效

String path =

getClass().getProtectionDomain().getCodeSource().getLocation().getPath()

<!--EndFragment-->


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

原文地址:https://54852.com/yw/7152392.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存