在java程序中获得Tomcat下的webapps绝对路径的程序怎么写?

2024-11-18 08:37:38
推荐回答(3个)
回答(1):

jsp中:request.getContextPath()
servlet、action中:
HttpSession session = request.getSession();
ServletContext application = session.getServletContext();
String serverRealPath = application.getRealPath("/") ;

回答(2):

File f = new File(getClass().getResource("/").getPath());
f = new File(f.getPath().replace("%20"," ") + "/databasePool.conf");

%20代表空格!

回答(3):

就是\啊