aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes How to retrieve entered web address in browser from java code. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to retrieve entered web address in browser from java code." Watch "How to retrieve entered web address in browser from java code." New topic
Author

How to retrieve entered web address in browser from java code.

Safi Khan
Greenhorn

Joined: Aug 11, 2012
Posts: 19
Dear All,

I wants to know how i can retrieve the entered web address in browser from my java code ?, Is there any specific API or how i can monitor http trrafic? so that from there i can get every entered url in browser.

Any help will be appreciated.

Thanks,
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8997
    
    9

Are you working with a bare socket, an applet or a servlet? The applet class has methods to get the URL it is loaded from. Servlets have a request object that has methods to obtain the request path.


[How To Ask Questions On JavaRanch]
Safi Khan
Greenhorn

Joined: Aug 11, 2012
Posts: 19
Are you working with a bare socket, an applet or a servlet? The applet class has methods to get the URL it is loaded from. Servlets have a request object that has methods to obtain the request path.
Joe Ess


I am working with a bare socket, actually i have a simple program which runs as a service in the background , i wants that program to get the every url that user enters in his/her browser.

Can you help?

Thanks,
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Safi Khan wrote:I am working with a bare socket, actually i have a simple program which runs as a service in the background , i wants that program to get the every url that user enters in his/her browser.


It sounds like you're trying to write a proxy server. Or at least, let me put it this way, if you did write a proxy server then it would naturally get every URL that the user entered in the browser. Provided that you configured the user's browser to connect via your proxy application.

In fact it would get every URL which the browser tried to connect to, regardless of whether the user entered it in the address bar or not.

But I think it would be helpful if you backed up a few steps and explained the background of this question. Right now it's unclear why you want to get URLs entered into the browser, and what your service has to do with that requirement.

Safi Khan
Greenhorn

Joined: Aug 11, 2012
Posts: 19

Thanks for the reply (Paul Clapham)

Here is the clarification,

I am not writing a proxy server, Actually i have a java program/service which has a list of predefined url's, now i wants my program to stop the user access to these url's from browser. So for this i need the entered url in browser so that i can compare and do my actions.

I am thinking about, how i can hava a socket which should start listening data from the browser socket so that when browser sends the http request, i should also get that object, Is it possible or any other idea.

Thanks,

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

Well, that's why you would use a proxy server. The proxy server inspects all requests from the browser and either passes them on to the web, or rejects them by sending a response itself. I'm posting this from my browser through a proxy server which does exactly that -- it doesn't block the Ranch, but it does block e.g. Facebook.
Don Ho
Greenhorn

Joined: Mar 07, 2012
Posts: 9

Another alternative would be to filter via DNS lookup, e.g. set custom entrys in the local hosts file or point your system to a custom DNS server.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to retrieve entered web address in browser from java code.