Link to home
Start Free TrialLog in
Avatar of yi02
yi02

asked on

How to invoke the browser and then output result of a java program into a html page displayed in the browser

Dear all:

I have a java program running on a PC that need to invoke the default browser (ideally prompt the user to download a browser: e.g. IE or Mozilla if user does not have a compatible browser installed) in the PC and output results (e.g. string text) from the java program into a html page (like tables or hyperlinks etc. in the html page) that will be displayed in the browser.

Anyone please provide example codes or suggestion how to do that would be greatly appreciated! Thanks.

best regards,

yi02
ASKER CERTIFIED SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of VolatileVoid
VolatileVoid

If you're sure you're running on a Windows PC (though this would be very OS dependent, obviously) you can do:
    Runtime.getRuntime ().exec (new String[] {"explorer.exe", fileName});
Where fileName is the name of the file you want to display.
First, a question, what's wrong with using Swings HTML browsing classes?

Secondly, you can locally write your output to an HTML file and then open it using Runtime.exec, however, instead of trying to execute a Browser's executable (i.e. explorer.exe), I'd try to invoke the HTML file itself and usually, that should get the OS to launch the currently configured Browser.
Avatar of yi02

ASKER

Dear doronb:

Your comments sound very much what I want. Could you please help me with a piece of sample codes. Appreciate it very much!

Thanks.

yi02
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So is it display HTML in a Swing component that you want or starting an external browser to display an HTML file? If using Swing, great. If you want to start an external browser then I'd suggest the material at the link I first posted is more directly related to that problem.
Avatar of yi02

ASKER

Dear jim_cakalic:

Very Sorry, I was away for a little away and just got a chance back to this question.

Regarding your question: So is it display HTML in a Swing component that you want or starting an external browser to display an HTML file?
Either ways are fine as long as the displayed content is in html format (e.g. if there is a hyperlink in the displayed html, clicking on it should jump to the intended url pointed by the hyperlink etc).

For the material at the link you first posted is Window-oriented, Is there more generic way (i.e. platform-independent)? Sorry I may mislead you by saying I run my program in PC, in fact, my program can run on other platform too, such as macintoch etc.

Thanks a lot.

yi02