Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing secure web pages with JTextPane

 
Dave Salter
Ranch Hand
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 293
Java Mac OS X Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic