?
Solved

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

Posted on 2005-04-11
7
Medium Priority
?
530 Views
Last Modified: 2008-03-03
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
0
Comment
Question by:yi02
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 600 total points
ID: 13754925
Hi,

I think this might be what you are looking for:
http://www.rgagnon.com/javadetails/java-0071.html

You'd probably generate the HTML into a local file and then supply a file URL when starting the browser so it will display what has been generated.

Regards,
Jim Cakalic
0
 
LVL 1

Expert Comment

by:VolatileVoid
ID: 13755362
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.
0
 
LVL 9

Expert Comment

by:doronb
ID: 13757446
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:yi02
ID: 13776964
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
0
 
LVL 9

Assisted Solution

by:doronb
doronb earned 600 total points
ID: 13778097
A sample code of using Swings HTML browsing classes can be found here:

1) http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
2) http://java.sun.com/docs/books/tutorial/uiswing/components/text.html

You can refer to this article about running external processes with Java:

http://www.codeproject.com/useritems/ProcessHelper.asp
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 13778520
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.
0
 

Author Comment

by:yi02
ID: 13974685
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

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question