aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Accessing secure web pages with JTextPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Accessing secure web pages with JTextPane" Watch "Accessing secure web pages with JTextPane" New topic
Author

Accessing secure web pages with JTextPane

Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

I'm using a JTextPane to display some data returned from a http web address. The website is secured via Basic authentication.

Is there any way I can tell the JTextPane my username and password programatically so the user authentication is transparent to the application user?

Thanks,

Dave.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
How do you retrieve the data to be displayed - an URLConnection? If so, you can set headers to deal with authentication. Check the Applet FAQ -linked in my signature- for an explanation (which is not applet-specific).
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

I call the setPage() method on the JTextPane passing it an HTTP Address.

Are you suggesting using a URLConnection to read the data into a string and then setting the HTML in the control to the string?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
Gosh, I never knew you could do that. But it doen't look to me like you can use advanced HTTP features with that method. I would think that it takes no more than 20 lines of code to open a HttpUrlConnection yourself, set the basic auth header, and retrieve the page contents. You could be done with that in an hour.
Dave Salter
Ranch Hand

Joined: Jul 20, 2005
Posts: 293

No, if you call setPage() with a URL, it doesn't seem to allow you to do anything advanced. I'll try the HttpUrlConnection. That sounds like the way ahead.

Thanks for the help.

Dave.
 
 
subject: Accessing secure web pages with JTextPane