wood burning stoves 2.0*
The moose likes Servlets and the fly likes Get the website name in the sevlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Get the website name in the sevlet" Watch "Get the website name in the sevlet" New topic
Author

Get the website name in the sevlet

koteswar sirikonda
Greenhorn

Joined: Sep 26, 2010
Posts: 1
HI, I have a requrement to know the website name from where the request has come from.
I created one link that can be used by any no of websites. If any one click on the link the request is come to my application. I want to know in which website the link has been clicked.
Can any one help me please.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can view the referrer information but that information is optional. Although most browser do sent it I've disabled it and it won't be send if the link is accessed directly so it won't work always.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

If the two web sites are under your control then set any request attributes in them , check them in your code .

If the two web sites were not in your control , access the IP address of this web sites and do your logic


Save India From Corruption - Anna Hazare.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Ravi Kiran Pattu wrote:access the IP address of this web sites
And how would you do that?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Look at the methods provided by the HttpServletRequest object.

http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/http/HttpServletRequest.html

With them you can find the domain, contextPath, IP, etc ...


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

But that is the ip address of the client. Not of the website on which the client clicked on the link.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Wouter Oet wrote:But that is the ip address of the client. Not of the website on which the client clicked on the link.



Yep, just re-read the OP's question (after a cup of coffee) and realized that he was looking for the info from the referrring site.

Thanks for pointing that out.
Bhoomika Bathla
Ranch Hand

Joined: Nov 28, 2009
Posts: 40
use this : -

String refererPage = request.getHeader("referer");

Try to print value of refererPage.It will print the name of website from which it is coming.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Bhoomika Bathla wrote:use this : -

String refererPage = request.getHeader("referer");

Try to print value of refererPage.It will print the name of website from which it is coming.


The referer header was already discussed earlier in this thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get the website name in the sevlet
 
Similar Threads
Server Name and URL
Need help with (SCMAD)
Eliminating recursion inTowers of Hanoi???
Server Name and URL
Original request referer in Action/Interceptor