user_1357
user_1357

Reputation: 7940

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.

Upvotes: 18

Views: 52055

Answers (3)

Mustafa Kannan
Mustafa Kannan

Reputation: 121

To get the source domain you can use request.getHeader("origin") especially if the requests have to pass through a proxy server.

Upvotes: 3

Olga
Olga

Reputation: 1

Hostname request

InetAddress ip = InetAddress.getLocalHost();
String hostname = ip.getHostName();
out.print("Your current IP address : " + ip+"\n");
out.print("Your current Hostname : " + hostname);

Upvotes: 0

adarshr
adarshr

Reputation: 62573

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(); 

Upvotes: 36

Related Questions