Mayumi Mayumi - 1 year ago 133
Java Question

Get URL of the request sender with HttpServletRequest

How do you get the source domain using HttpServletRequest?
Source domain is the requester's domain.

Thanks.

Answer Source

You could do either

// gets client (browser)'s hostname
String host = request.getRemoteHost(); 

OR

// get the server's domain name.
String domain = new URL(request.getRequestURL().toString()).getHost();