open browser from java program with post parameter

2019-07-21 09:45发布

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?

2条回答
神经病院院长
2楼-- · 2019-07-21 10:09

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

查看更多
倾城 Initia
3楼-- · 2019-07-21 10:31

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

查看更多
登录 后发表回答