open browser from java program with post parameter prefilled

你说的曾经没有我的故事 提交于 2019-12-11 00:22:59

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/11653045/open-browser-from-java-program-with-post-parameter-prefilled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!