Question

I have a java program, where i can open a Internet Explorer or Any Browser. using Runtime.getRuntime().exec(cmd);

But I want to open a browser from my java program mentioning url and post parameter.

First of all, is this possible? How can i achieve this?

Was it helpful?

Solution

You can appled the URL to the command line parameter for example in IE:

C:\Windows\System32>"C:\Program Files (x86)\Internet Explorer\iexplore.exe" http://stackoverflow.com/

Firefox:

C:\Windows\System32>"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" stackov
erflow.com

and Chrome:

C:\Windows\System32>"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
" stackoverflow.com

Works on windows, you will need to replace C:\Windows\System32>"C:\Program Files (x86)\Google\Chrome\Application with the the location of the application in your environment

OTHER TIPS

There isn't much you can do about this. Unless the browser you are opening has some available command line arguments (you'd have to look them up, and they would be browser specific), you won't be able to do it.

May I suggest using a Java browser window:

The SWT Browser object has a fairly large API, and will use a native browser for rendering the pages.

Specifically this snippet will do what you're looking for:

http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet330.java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top