如何获取servlet所在的主机名(带端口) [英] How can I get a the host name (with port) that a servlet is at

查看:562
本文介绍了如何获取servlet所在的主机名(带端口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为ServletContext可能会提供一种方法。 ServletContext的getAttribute()方法是否提供任何帮助,即是否有帮助的属性名称(可能是host,port)。

I thought ServletContext might provide a method. Does the getAttribute() method of ServletContext provide any help i.e. is there an attribute name (maybe "host", "port") that will be of help.

原因为此,我希望我的应用程序在部署的任何地方运行,并且我必须允许用户单击指向文件服务器上某个位置的链接。因此我需要通过主机和端口引用,不能使用内部引用。

The reason for this is I want my application to run wherever it is deployed, and at one point I have to allow a user to click a link that points to a location on the file server. Hence I need to reference by the host and port and cannot use an internal reference.

推荐答案

ServletRequest.getServerName(...)
ServletRequest.getServerPort(...)

这篇关于如何获取servlet所在的主机名(带端口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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