Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling browser from Standalone Java application

 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Does any body knows how to call or instantiate default browser and show some html page from standalone application(Not from applet)?
any example is help full
Mohana
 
Thomas Suer
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I know:
in the java.lang.Runtime class there is a method called 'exec()'. With this method you can run any program. All you have to do is pass the browser's 'exe'-file name and its parameters to load the desired html-file.
What I don't know:
how to get the default browser.
Good luck!
Tom
[This message has been edited by Thomas Suer (edited October 30, 2001).]
 
george justin
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can try this out
String[] param = {"c:\\program files\\plus!\\microsoftinternet\\iexplore.exe","www.javaranch.com"};
Runtime r = Runtime.getRuntime();
Process p = null;
try
{
p = r.exec(param);
}
catch(Exception e)
{
System.out.println("Error executing " + e);
}
Bye
George Justin
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you need the browser to render some specific html page, than use JEditorPane (or was it JTextPane?) to do that. theres lots of documentation about this with sample code (java.sun.com).
chantal
 
Jeremy Hooie
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way of doing this to use the Windows start command.

Since HTML files are bound to the default browser, you don't even have to specify the browser.

You will need to implement your own start script on other platforms.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of windows does "start" work on? It doesn't work on my WinNT box here at work... The way I've always seen it done is either the program assumes you have a certain browser installed in a certain place, or when you install or the first time you click on a button that would launch the browser, you have to specify which browser you want to run ( usually the program opens up a file dialog to get this info... )

-Nate
 
Bigglesworth Naruki
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Really? I was under the impression that START works on all 32-bit Windows platforms. Try it from a DOS prompt. Maybe your path is screwed up...
Originally posted by Nathan Pruett:
What version of windows does "start" work on? It doesn't work on my WinNT box here at work... The way I've always seen it done is either the program assumes you have a certain browser installed in a certain place, or when you install or the first time you click on a button that would launch the browser, you have to specify which browser you want to run ( usually the program opens up a file dialog to get this info... )

-Nate

 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Thanks a lot for your replies.
we can do use
Runtime.getRuntime().exec("start iexplore [webaddress or file]");
or
Runtime.getRuntime().exec("http://www.webaddress.com");
But, it's depends on type of windows Operating system we use.
If I want to know path of default browser exe file.
Is there any mechanisam to get it irrespective of type of windows
platform?
If that can be possible, we can make standalone application
atleast independent of different windows platforms.
thanks in advance,
Mohana
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy ( & Bigglesworth ),
Sorry... "start" launches a new command-prompt window at the command prompt... I was trying it from the "Run..." option in the start menu... I guess you learn something new every day...

Mohana,
There is no way to get the path of the default browser from the OS... remember, Java is a platform independent language, and most OS's don't support the "default" browser idea. What if, instead of running in any version of windows, a user wanted to run your program under Linux? The best thing to do is probably ask the user when installing, or when trying to access the browser for the first time, and save that path somewhere so you can access it later.

-Nate
 
bkrasnof
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check out (the first 2 links expand on work that the javaworld article started):
http://www.stanford.edu/~ejalbert/software/BrowserLauncher/
and
http://ostermiller.org/utils/Browser.html
and
http://www.javaworld.com/javaworld/javatips/jw-javatip66.html
 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nathan
Getting browser path while stalling may not viable solution.
No user like to find and give paths to something while installing.(unless user is a developer also ;-)

The URL s given by bkrasnof is very good.
They have given few more options for calling default browser.
There is a free software which takes case of platform and other issues itself.
I tested in Windows NT. It's is working fine.
Java tips of java world has given some code for two platforms. it may not be useful since, it's ristricted platform.
But useful for those platforms since code is small.
greate feedbacks, more possiblities, thanks every body.
Mohana
 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
I used Runtime class to get default browser. it's giving exception.(Windows NT platform)
I need to use local address to get html page
String strWebAddress = "E:/JRE1.3/myfolder/myinfo/001+020+009.html";
Runtime.getRuntime().exec("start iexplore "+strWebAddress);
java.io.IOException: CreateProcess: start iexplore E:/JRE1.3/myfolder/myinfo/001+020+009.html error=2
If i cut and paste same at command prompt it's works some times and does not work sometimes.( no idea why and when it does not work)
What could be the problem? What is this error=2 means?
Thanks in advance
Mohana
 
mohana konakanchi
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Could some body give some reply on my previous posting.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic