I'm using wicket 1.5.1, couldn't figure this out.
public class MyPage extends WebPage {
public MyPage() {
String clientAddress = ...?
I'm using wicket 1.5.1, couldn't figure this out.
public class MyPage extends WebPage {
public MyPage() {
String clientAddress = ...?
WebRequest req = (WebRequest) RequestCycle.get().getRequest();
HttpServletRequest httpReq = (HttpServletRequest) req.getContainerRequest();
String clientAddress = httpReq.getRemoteHost();
getRemoteAddr()
will return the raw IP address, while getRemoteHost()
will return the resolved address name if possible (or the IP if not). –
Gilmour Subclass WebClientInfo
to provide a public method that delegates on protected WebClientInfo.getRemoteAddr()
. Then create a method to query this in a custom RequestCycle
class. In Wicket 1.3-1.4 I've achieved this by subclassing RequestCycle
, but with 1.5 it seems things are different: RequestCycle in Wicket 1.5
WebClientInfo
has the advantage of querying the X-Forwarded-For
erquest parameter, and will return the proper IP address if your server is behind a proxy/load balancer that uses XFF.
Using Wicket 6 and 7, you can do the following:
String remoteAddress = ((WebClientInfo)Session.get().getClientInfo())
.getProperties()
.getRemoteAddress();
© 2022 - 2024 — McMap. All rights reserved.
httpReq.getRemoteAddr()
? – Sandarac