Java EE:如何获取我的应用程序的URL? [英] Java EE: how to get the URL of my application?

查看:136
本文介绍了Java EE:如何获取我的应用程序的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java EE中,如何动态检索应用程序的完整URL?

In Java EE, how can I dynamically retrieve the full URL for my application?

例如,如果URL是localhost:8080 / myapplication /,我想要一个方法可以简单地将它作为字符串或其他内容返回给我。

For example, if the URL is "localhost:8080/myapplication/", I would like a method that can simply return this to me, either as a String or something else.

我正在运行GlassFish作为应用程序服务器。

I am running GlassFish as application server.

推荐答案

在任何servlet或过滤器中,您都可以访问 HttpServletRequest ,它允许您查看客户端使用的URL你的申请,例如尝试 HttpServletRequest。 getRequestURL()

Inside any servlet or filter you have access to HttpServletRequest which allows you to see what URL was used by the client to access your application, e.g. try HttpServletRequest.getRequestURL().

这篇关于Java EE:如何获取我的应用程序的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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