如果上下文和根名称不同,则获取 Java Web 应用程序中的根目录名称 [英] Get the root directory name in Java web application if context and root names are different

查看:65
本文介绍了如果上下文和根名称不同,则获取 Java Web 应用程序中的根目录名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Web 应用程序,其中上下文名称与我的根名称不同.例如,我的根目录名称是 myapp,上下文路径是 app.那么如何从Java Web应用程序中获取根名称(myapp)?

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?

推荐答案

如果应用程序没有使用 war 文件部署,您可以使用此代码返回应用程序运行的完整地址.

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("/");

我提供的代码是我在我的一个 Java EE 项目中使用的代码,由于某些原因我没有将我的项目部署为 war 文件

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

这篇关于如果上下文和根名称不同,则获取 Java Web 应用程序中的根目录名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆