I have a requirement that my java application should open a web browser when user click on a button and thereafter the web browser open up a page in which user have two options "Agree" and "Not Agree", depending on the button he clicks on, some code comes in the browser in the address bar. I want to fetch that uri back into my java application.

You can try to use Selenium

You can try to use Selenium

Thanks for telling me a new thing. But does Java itself have no feature like this?

Fast answer, no. Only through external libraries/projects like Selenium

ok.. Do you know any tutorial for using selenium with java?

I haven't tried this myself but...
Java 6 has the new Desktop API that allows you to open the user's default web browser with a URI of your choice
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/
presumably if this is a page that you have written (maybe embedding a remote page in a frame) then you can POST back whatever you need?

Ya I am aware of it that I can open default web browser from my java app with a specified uri. But I am just not getting any idea how to fetch any data back from the browser.

Can you elaborate your last line, what you really mean by"maybe embedding a remote page in a frame) then you can POST back whatever you need?"

how to fetch any data back from the browser

Have the browser load its html page from your code (make it a simple server) then when the browser sends a response to the html page it will go to your code.

Have the browser load its html page from your code (make it a simple server) then when the browser sends a response to the html page it will go to your code.

My code can just open the default web browser to a link. And the page it is going to load is not mine, the page is loaded from some company's server. So I can not modify it in anyway.

Your server could be a proxy and pass the page thru to the browser.

Your server could be a proxy and pass the page thru to the browser.

That would be very complex, I think. What do you mean, I can use a third party proxy or I should code it on my own?

What about embedding a web browser in app?

Is there a browser that you can interface with that closely?

No, I have no idea. That is why I was asking, is it possible without much overhead?

It sounds like you're trying to re-direct another site's content through your app after verification and I would question the legality/ethics of that?

Perhaps you can clarify a bit, because this may be walking the edge of our Keep It Legal rules.

It sounds like you're trying to re-direct another site's content through your app after verification and I would question the legality/ethics of that?

Perhaps you can clarify a bit, because this may be walking the edge of our Keep It Legal rules.

Yeah, it is legit. Actually I am just going to open an authorization page for my app. Or to be exact it is for the facebook app. Depending on user's ans facebook will give me some code in the browser's address bar which is then required to complete the authorization process.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.