Get the root directory name in Java web application if context and root names are different

无人久伴 提交于 2019-12-11 06:48:09

问题


I have a web application where the context name is different from my root name. For example my root Dir name is myapp and the context path is app. Then how to get the root name (myapp) from the Java web application?


回答1:


If the application is not deployed with a war file you can use this code that will return the whole address where the application is running.

//request variable is the Java HTTP servlet request object received from an action 
request.getSession().getServletContext().getRealPath("/");

The code I had given is the one I used in one of my Java EE projects well I didn't deploy my project as a war file due to some reasons

and getting the web application location can be used to get your root directory name



来源:https://stackoverflow.com/questions/14082132/get-the-root-directory-name-in-java-web-application-if-context-and-root-names-ar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!