如何获取appengine应用程序的当前服务器URL

如何获取appengine应用程序的当前服务器URL

本文介绍了如何获取appengine应用程序的当前服务器URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图从代码中获取当前正在运行的appengine java应用程序的服务器URL。也就是说,如果应用程序在我的本地开发机器上运行,我想以某种方式返回 http:// localhost:8080 但如果它在prod中运行,我想返回 http://myappid.appspot.com 。有没有可以做到这一点的Java或Appengine API?我希望没有手动更改和从配置文件或常量中读取。I'm trying to get the server URL of a currently running appengine java app from code. That is, if the app is running on my local dev machine I would like to somehow get returned "http://localhost:8080" but if it is running in prod I'd like to be returned "http://myappid.appspot.com". Are there any java or appengine API's that can do this? I'd like to not have a to manually change and read from a config file or a constant.谢谢。 Aleem推荐答案您应该可以使用getServerName():You should be able to use getServerName():boolean local = "localhost".equals(httpServletRequest.getServerName());如果您需要更多信息,还可以使用其他方法。 getServerPort()。There are other methods you can also use if you need more info, e.g. getServerPort(). 这篇关于如何获取appengine应用程序的当前服务器URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 07:19