如何使用apache wicket 1.54获取服务器变量? [英] How can I obtain server variables using apache wicket 1.54?
本文介绍了如何使用apache wicket 1.54获取服务器变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取运行我的Web应用程序的当前服务器的名称和IP.我不确定该如何执行检票口1.54.我需要知道如何获取服务器变量.
I am trying to get the name and ip of the current server in which my web application is running on. I am not sure how to do this is wicket 1.54. I need to know how to get at my server variables.
在检票口1.4中,您可以执行以下操作:
In wicket 1.4 you could do:
HttpServletRequest hsr = getWebRequestCycle().getWebRequest().getHttpServletRequest();
然后,您可以使用hsr来获取标头或属性.
Then you could use hsr to grab headers or attributes.
在检票口1.54中,等效行是:
In wicket 1.54 the equivalent line is:
HttpServletRequest hsr = (HttpServletRequest)getRequestCycle().getRequest().getContainerRequest();
hsr.getAttribute("SERVER_NAME");
但是我总是得到一个空字符串.
However I always am getting a null string.
推荐答案
这对我在WebPage中使用Wicket 1.5.5有用:
This works for me with Wicket 1.5.5 inside a WebPage:
HttpServletRequest request = (HttpServletRequest) getRequest().getContainerRequest();
String serverName = request.getServerName();
String remoteAddr = request.getRemoteAddr();
这篇关于如何使用apache wicket 1.54获取服务器变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文