0

I have one URL lets say (www.example.com). When I hit this URL using below code it will be opened in system default browser.In the browser it will ask user to enter username and password . Then he has to enter username and password. If they are correct again the page will be redirected to (www.example.com).Now i have to get header value "isSuccess" form the browser.If it is normal web application i can achieve it using "request.getHeader("isSuccess")". But How can I achieve the same in Swing Application?

//Swing code to open URL in default browser
Desktop d=Desktop.getDesktop();
d.browse(new URI("http://www.example.com")); 

Note : Due to security reasons I used dummy URLs above.

Baz
  • 36,440
  • 11
  • 68
  • 94
Madhu Sudhan Reddy
  • 607
  • 5
  • 15
  • 22
  • You cannot get the header value using this approach. The control is passed to the native default browser once you execute `d.browse(..` and from then your program isn't control of the browser. – Mubin Mar 02 '15 at 14:29

1 Answers1

0

You can't do it using Desktop. All Desktop.browse() does is tell the default browser to open a URL. Just as if you navigated to a certain URL in your favorite browser, it doesn't display the HTTP header information for you to see.

Two options. First using a browser inside of you Swing applications, such as with this: http://djproject.sourceforge.net/ns/index.html

Second, using a custom protocol. In this case a web page, such as your success page, can send a message to an installed application. You'll have to have a different solution per platform though (OS X JRE 6, OS X JRE 7, look at documentation on how to add a custom protocol, Windows).

Community
  • 1
  • 1
martinez314
  • 12,162
  • 5
  • 36
  • 63