• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing secure web pages with JTextPane

 
Ranch Hand
Posts: 293
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac OS X Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic