1

I'm developing a console Java application(Not swing) using java.awt.Desktop class, which will launch the browser with something like this;

Desktop.getDesktop().browse(URI.create("http://www.google.com"));

This works, but actually what i want is not to give an absolute URL but to display a string with HTML content which I have builded in the code. Can I directly do do this without saving my content as a html page and then calling again?

String myHtmlstring="<body>.."
Christian Hujer
  • 17,035
  • 5
  • 40
  • 47
Spring
  • 11,333
  • 29
  • 116
  • 185

2 Answers2

1

Its not particularly clear what you're asking for though, what do you mean when you say, "display my own html string?" Do you want to generate html and then have the browser display that?

JavaFX 2.0 comes with a webkit component, and you can embed that in your swing application and do with it what you will. Its officially released for Windows and in [beta|preview|alpha] for max/linux. So if you don't require support for multiple platforms right now, its probably a good choice.

BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
1

For this to work, you would need an browser, which can be started with the html-content as parameter.

 firefox -code "<html><head><title>demo</title></head><body>..."

If you look at the manpages for firefox, lynx and opera, you won't find such an option (I didn't). But theoretically, it would be possible.

Since html-pages are normally some kb big, using the parameters would be very unhandy, because html often contains quotes and apostrophes, which would need masking. Therefore, if a passing of content would be possible, I would expect it as reading from stdin like so:

  cat demo.html | browser 

However, I don't know a browser which supports this.

Summary: No, it's not possible with today browsers, but in principle it would be possible. Going with temporary files would be the solution, you're already aware off.

user unknown
  • 35,537
  • 11
  • 75
  • 121