如何获取 servlet 所在的主机名(带端口) [英] How can I get a the host name (with port) that a servlet is at
本文介绍了如何获取 servlet 所在的主机名(带端口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为 ServletContext 可能提供了一种方法.ServletContext 的 getAttribute() 方法是否提供任何帮助,即是否有一个有用的属性名称(可能是主机"、端口").
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屋!
查看全文