web-applications - 在 Servlet 中获取 Web 应用程序名称

我正在开发可用于多个 Web 应用程序的通用工件。开发人员只需将我的监听器类添加到他们的 web.xml 中。在我的监听器中,我需要获取运行我的代码的 Web 应用程序名称。

虽然 getServletContextName() 会给出一个名称,但这个名称是在 web.xml 中编码的显示名称。我认为显示名称是可选的,因此它不可靠。所以我想获取实际的 Web 应用程序名称。有没有办法做到这一点?

感谢您的关注。

最佳答案

试试这段代码

String ApplicationName = ((HttpServletRequest) request).getContextPath()
                    .replace("/", "");

https://stackoverflow.com/questions/12308708/

相关文章:

quartz-scheduler - 使用简单的xml来驱动Quartz Scheduler

export-to-excel - SSIS导出到excel

c# - XML Serializer 不序列化具有公共(public) getter 但没有 se

python - 使用 idapython 进行线程化

c# - 哪个类需要实现 INotifyDataErrorInfo?

c# - 是否可以在 MS Access 中执行批量插入

regex - 允许方括号的正则表达式

php - 使用ghostscript输出文件目录

cassandra - 如何将两个 Cassandra 集群合并为一个?

php - 在根域 (www) 上启动一个 php $_SESSION 并跨子域共享 session