Launhing browser from java
Hi
I'm Launching jsp from my java code with the help of Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + strUrl); when this jsp is Launched it passes the parameters to another jsp with action property of form.and the new browser is Launched what i want to do is when this browser is launched i want to customize the browser visibility.Like hiding toollbar.setting scrollability false etc. can someone guide me how to perform this
You need to use javaScript for this, not java, have a google, theres loads of javaScript stuff on the web.
Similar Messages
-
Launching Browser from Java when Browser URL is very long
Hi,
I am trying to launch a browser from Java.
I am doing the following.
String command = "cmd" + "/c" + "start" + " browserURL";
Process p = Runtime.getRuntime()exec(command);
Note: My browserURL is very long.
Now the browser is invoked. But the URL shown is incomplete and hence
browser is unable to open the required application.
Can someone help me in this.
One way is to increase the buffer size on the command prompt?
Is there any java command for this?
Is there any other way to solve this issue.
Thanks,
ARthis is my second time posting this, take note of it. I can't remember where i got it from, but credits go to the person that wrote it. It has helped me out thousands of times!!!
to use, compile, then call from your program:
org.newio.utils.BrowserLauncher.openURL("your url here")dfwtc
package org.newio.utils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.*;
public class BrowserLauncher
private static int jvm;
private static Object browser;
private static boolean loadedWithoutErrors;
private static Class mrjFileUtilsClass;
private static Class mrjOSTypeClass;
private static Class macOSErrorClass;
private static Class aeDescClass;
private static Constructor aeTargetConstructor;
private static Constructor appleEventConstructor;
private static Constructor aeDescConstructor;
private static Method findFolder;
private static Method getFileType;
private static Method makeOSType;
private static Method putParameter;
private static Method sendNoReply;
private static Object kSystemFolderType;
private static Integer keyDirectObject;
private static Integer kAutoGenerateReturnID;
private static Integer kAnyTransactionID;
private static final int MRJ_2_0 = 0;
private static final int MRJ_2_1 = 1;
private static final int WINDOWS_NT = 2;
private static final int WINDOWS_9x = 3;
private static final int OTHER = -1;
private static final String FINDER_TYPE = "FNDR";
private static final String FINDER_CREATOR = "MACS";
private static final String GURL_EVENT = "GURL";
private static final String FIRST_WINDOWS_PARAMETER = "/c";
private static final String SECOND_WINDOWS_PARAMETER = "start";
private static final String NETSCAPE_OPEN_PARAMETER_START = " -remote 'openURL(";
private static final String NETSCAPE_OPEN_PARAMETER_END = ")'";
private static String errorMessage;
private BrowserLauncher()
private static boolean loadClasses()
switch(jvm)
default:
break;
case 0: // '\0'
try
Class aeTargetClass = Class.forName("com.apple.MacOS.AETarget");
macOSErrorClass = Class.forName("com.apple.MacOS.MacOSError");
Class osUtilsClass = Class.forName("com.apple.MacOS.OSUtils");
Class appleEventClass = Class.forName("com.apple.MacOS.AppleEvent");
Class aeClass = Class.forName("com.apple.MacOS.ae");
aeDescClass = Class.forName("com.apple.MacOS.AEDesc");
aeTargetConstructor = aeTargetClass.getDeclaredConstructor(new Class[] {
Integer.TYPE
appleEventConstructor = appleEventClass.getDeclaredConstructor(new Class[] {
Integer.TYPE, Integer.TYPE, aeTargetClass, Integer.TYPE, Integer.TYPE
aeDescConstructor = aeDescClass.getDeclaredConstructor(new Class[] {
java.lang.String.class
makeOSType = osUtilsClass.getDeclaredMethod("makeOSType", new Class[] {
java.lang.String.class
putParameter = appleEventClass.getDeclaredMethod("putParameter", new Class[] {
Integer.TYPE, aeDescClass
sendNoReply = appleEventClass.getDeclaredMethod("sendNoReply", new Class[0]);
Field keyDirectObjectField = aeClass.getDeclaredField("keyDirectObject");
keyDirectObject = (Integer)keyDirectObjectField.get(null);
Field autoGenerateReturnIDField = appleEventClass.getDeclaredField("kAutoGenerateReturnID");
kAutoGenerateReturnID = (Integer)autoGenerateReturnIDField.get(null);
Field anyTransactionIDField = appleEventClass.getDeclaredField("kAnyTransactionID");
kAnyTransactionID = (Integer)anyTransactionIDField.get(null);
break;
catch(ClassNotFoundException cnfe)
errorMessage = cnfe.getMessage();
return false;
catch(NoSuchMethodException nsme)
errorMessage = nsme.getMessage();
return false;
catch(NoSuchFieldException nsfe)
errorMessage = nsfe.getMessage();
return false;
catch(IllegalAccessException iae)
errorMessage = iae.getMessage();
return false;
case 1: // '\001'
try
mrjFileUtilsClass = Class.forName("com.apple.mrj.MRJFileUtils");
mrjOSTypeClass = Class.forName("com.apple.mrj.MRJOSType");
Field systemFolderField = mrjFileUtilsClass.getDeclaredField("kSystemFolderType");
kSystemFolderType = systemFolderField.get(null);
findFolder = mrjFileUtilsClass.getDeclaredMethod("findFolder", new Class[] {
mrjOSTypeClass
getFileType = mrjFileUtilsClass.getDeclaredMethod("getFileType", new Class[] {
java.io.File.class
break;
catch(ClassNotFoundException cnfe)
errorMessage = cnfe.getMessage();
return false;
catch(NoSuchFieldException nsfe)
errorMessage = nsfe.getMessage();
return false;
catch(NoSuchMethodException nsme)
errorMessage = nsme.getMessage();
return false;
catch(SecurityException se)
errorMessage = se.getMessage();
return false;
catch(IllegalAccessException iae)
errorMessage = iae.getMessage();
return false;
return true;
private static Object locateBrowser()
if(browser != null)
return browser;
switch(jvm)
case 0: // '\0'
try
Integer finderCreatorCode = (Integer)makeOSType.invoke(null, new Object[] {
"MACS"
Object aeTarget = aeTargetConstructor.newInstance(new Object[] {
finderCreatorCode
Integer gurlType = (Integer)makeOSType.invoke(null, new Object[] {
"GURL"
Object appleEvent = appleEventConstructor.newInstance(new Object[] {
gurlType, gurlType, aeTarget, kAutoGenerateReturnID, kAnyTransactionID
return appleEvent;
catch(IllegalAccessException iae)
browser = null;
errorMessage = iae.getMessage();
return browser;
catch(InstantiationException ie)
browser = null;
errorMessage = ie.getMessage();
return browser;
catch(InvocationTargetException ite)
browser = null;
errorMessage = ite.getMessage();
return browser;
case 1: // '\001'
File systemFolder;
try
systemFolder = (File)findFolder.invoke(null, new Object[] {
kSystemFolderType
catch(IllegalArgumentException iare)
browser = null;
errorMessage = iare.getMessage();
return browser;
catch(IllegalAccessException iae)
browser = null;
errorMessage = iae.getMessage();
return browser;
catch(InvocationTargetException ite)
browser = null;
errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
return browser;
String systemFolderFiles[] = systemFolder.list();
for(int i = 0; i < systemFolderFiles.length; i++)
try
File file = new File(systemFolder, systemFolderFiles);
if(file.isFile())
Object fileType = getFileType.invoke(null, new Object[] {
file
if("FNDR".equals(fileType.toString()))
browser = file.toString();
return browser;
catch(IllegalArgumentException iare)
browser = browser;
errorMessage = iare.getMessage();
return null;
catch(IllegalAccessException iae)
browser = null;
errorMessage = iae.getMessage();
return browser;
catch(InvocationTargetException ite)
browser = null;
errorMessage = ite.getTargetException().getClass() + ": " + ite.getTargetException().getMessage();
return browser;
browser = null;
break;
case 2: // '\002'
browser = "cmd.exe";
break;
case 3: // '\003'
browser = "command.com";
break;
case -1:
default:
browser = "netscape";
break;
return browser;
public static void openURL(String url)
throws IOException
if(!loadedWithoutErrors)
throw new IOException("Exception in finding browser: " + errorMessage);
Object browser = locateBrowser();
if(browser == null)
throw new IOException("Unable to locate browser: " + errorMessage);
switch(jvm)
case 0: // '\0'
Object aeDesc = null;
try
try
aeDesc = aeDescConstructor.newInstance(new Object[] {
url
putParameter.invoke(browser, new Object[] {
keyDirectObject, aeDesc
sendNoReply.invoke(browser, new Object[0]);
catch(InvocationTargetException ite)
throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
catch(IllegalAccessException iae)
throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
catch(InstantiationException ie)
throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
break;
finally
aeDesc = null;
browser = null;
case 1: // '\001'
Runtime.getRuntime().exec(new String[] {
(String)browser, url
break;
case 2: // '\002'
case 3: // '\003'
Runtime.getRuntime().exec(new String[] {
(String)browser, "/c", "start", url
break;
case -1:
Process process = Runtime.getRuntime().exec((String)browser + " -remote 'openURL(" + url + ")'");
try
int exitCode = process.waitFor();
if(exitCode != 0)
Runtime.getRuntime().exec(new String[] {
(String)browser, url
catch(InterruptedException ie)
throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
break;
default:
Runtime.getRuntime().exec(new String[] {
(String)browser, url
break;
static
loadedWithoutErrors = true;
String osName = System.getProperty("os.name");
if("Mac OS".equals(osName))
String mrjVersion = System.getProperty("mrj.version");
String majorMRJVersion = mrjVersion.substring(0, 3);
try
double version = Double.valueOf(majorMRJVersion).doubleValue();
if(version == 2D)
jvm = 0;
} else
if(version >= 2.1000000000000001D)
jvm = 1;
} else
loadedWithoutErrors = false;
errorMessage = "Unsupported MRJ version: " + version;
catch(NumberFormatException numberformatexception)
loadedWithoutErrors = false;
errorMessage = "Invalid MRJ version: " + mrjVersion;
} else
if(osName.startsWith("Windows"))
if(osName.indexOf("9") != -1)
jvm = 3;
} else
jvm = 2;
} else
jvm = -1;
if(loadedWithoutErrors)
loadedWithoutErrors = loadClasses();
suck my balls -
Close parent window of Mozilla browser from Java
Hi All,
I want to open a URL in a controlled browser from java stand alone application. I was able to do this in Netscape of UNIX OS. The method followed is given below.
1. Launch a temporary HTML file which contains Javascript (to launch the URL in a controlled window). This is done using --- Runtime.getRuntime().exec() method.
2. Close the parent HTML file on 'onLoad' using Javascript. (self.close).
[ I tried window.close() & top.close() also.]
Now I need to support the same for "Mozilla" also. But mozilla just ignores the close() command of Javascript.
1. Is there any alternative way to close the parent window in Mozilla browser ?
2. Is there any way to close the parent window from java by using 'Process' class/ threads/ ??
3. Any other way???
Note : I am using the intermediate window for using Javascript. (controlling the browser properties). Since Java cannot communicate to Javascript directly, I am forced to have such an intermediate HTML file.
Thanks in advance.
surekha_Venugopal.Some more details :
Mozilla browser will close a window using window.close() command, but only if the window is opened by the script. If not it will not close it.
Here, I am opening the window from Java application. That is why closure of the window is failing.
Trying to find a solution.
Regards,
Surekha_Venogopal -
Easiest way to launch a link to the default browser from java?
Is there an easy way to launch a link in the default browser from java? Ideally I would have a graphic in a cell that when clicked on would open a new window/tab in the default browser. This would be done in SWT, but it might be similar to swing, awt, etc. Any ideas?
If you are using Java 1.5 or earlier, I found the browser launch code found here to work fairly well: http://www.centerkey.com/java/browser
-
Controlling a browser from java
hello experts,
i want to open an web dynpro URL in a browser and navigate through the URL , like putting values in the input box and click the buttons from java code .
Actually it is exactly like an automated test tool in java to navigate and render the given web dynpro URL with the test data given.
its very please help.
Regards,
KarthikHello Karthik,
I'm using Selenium to do something similar. You can find more information at http://seleniumhq.org/
The documentation can be found at http://seleniumhq.org/documentation/ and you can find a tutorial implementation for Java at http://seleniumhq.org/documentation/tutorials/
You can use a new Java Project to start using Selenium, just in case you feel confused.
I've been using Selenium for some time now, you will learn some tricks during the way. And you'd probably take a look on waitForCondition function, since you'd need some calls in order to wait for webdynpro ajax requests to populate tables (before doing your assertions).
Hope it helps.
Regards,
Daniel -
How to open a web browser from java
Hi
Would anybody please help me with this. I need to open a web browser from my java app but I don't know. What method I can use?
Thanks.
Hung.You can use the Runtime class for this. It can run any command. So, you can run the .exe file of your Web browser.
The following code will run Internet Explorer (assuming iexplorer.exe is in C:\Program Files\Internet Explorer):
import java.lang.Runtime;
public class Explore{
public static void main(String[] args) {
try{
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\iexplore");
}catch (Exception e) {
System.out.println("Exception: " + e); -
How to control browser from java program?
I want to retrieve the url currently loaded in my default browser. How to achieve this task using java program? I dont know how to access browser using java.
Peter__Lawrey wrote:
Actually Desktop.open only works for downloaded pages.
Instead you can use this to get the browser to download the page and display it.
Desktop.getDesktop().browse(URI.create("http://www.google.co.uk"));
First of all thanks for your reply Mr Peter__Lawrey.
I want to just retrieve the urls loaded in the default webbrowser, not the content of the url or the task of opening the default browser with the specific url. -
How to invoke browser from java program in Solaris ?
Hi all,
Is there any way by which a browser can be opened with specific URL, from a java program in solaris OS ?
In windows I am able to do so by using "rundll32 url.dll,FileProtocolHandler".
Thanks,
ngsWell, how is a browser normally invoked on Solaris? And have a look at JDIC, maybe it helps you.
-
Problem with opening browser from Java app.
Hi guys, I'm not sure if this is the right place to post this, so please excuse me if I'm wrong. I'm trying to open an html page (it's a help file) from a Java application. I'm currently using java.awt.Desktop. browse(URI uri); which gets the job done, as long as I don't pass any parameters to the page. (e.g. http://www.site.com/site.html?param1=1). Doing that gives me an IOException. Is there a way to do this without using the JNLP API?
This is the file path copied directly from the browser's address bar:
file:///home/riaan/EMCHelp/Help.html?page=WorkFlowActivityCategory.html"{code}
Which causes the app to throw an exception, but when I change it to:
{code}file:///home/riaan/EMCHelp/Help.html{code}
it opens Help.html in the browser. That's why I thought that it might be the query that's a problem. Perhaps it's a simple issue of not escaping a character or something that I failed to see. -
Lauch IE browser from Java Application
Hi, I am interested in launching an IE window from a Java application. Is there a way
to accomplish this? Thanks.Again, any other way that allows me to start a java application and IE browser on WINDOWS2000 would be helpful too.
-
Open web browser from java application to specific page
Hi,
I used the code from http://www.javaworld.com/javaworld/javatips/jw-javatip66.html to open a web browser to a specific URL. That worked great! However, I run into a problem if the URL targets a specific page, for example, "http://www.yahoo.com/news.html" would give me an problem with the shortcut problem. Any ideas how to get around that?
The command rundll32 url.dll,FileProtocolHandler http://www.yahoo.com/news/ would work fine, except anything ends with .htm or .html.
Thanks,
DavidIt looks like url.dll doesnt like .htm or .html files. For more info look here: http://www.jsiinc.com/SUBI/tip4100/rh4162.htm
For some reason it is confused by the 'm' character in .html which is odd considering it has no problems with .com
So if you want to keep using url.dll, do something like this:
replace ".htm" with ".ht%6D" -
Opening new default browser from java app
Hi There,
I would like to know if there is away to execute the following in a Java app that will open a new browser window.......in other words, I don't want it to take over the already opened window - just open a new window every time.
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler
www.google.co.nz");Any help with this would be greatly receievd.There might be. However it would be done by modifying that Windows-specific command that you have in red there. As such it's nothing to do with Java. Searching in Windows-specific websites might get you somewhere.
However Firefox gives the choice (new window, new tab, or same tab in same window) to the user as a configuration option, so I wouldn't bet on getting somewhere. I don't know if IE has a similar configuration option. -
Open Browser with No Address Bar from Java
How to open a IE Browser from Java with no address bar, tool bar etc ?
I am able to open browser like the listed code, but the requirement for me is it has to open with no "Address Bar", buttons.
I know we can do that in "Javascript" but how to or is there a way to do that in java/swing.
Any help is greatly appreciated.
String WIN_FLAG = "url.dll,FileProtocolHandler";
String WIN_PATH = "rundll32";
String url = "www.google.com"
String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
Runtime.getRuntime().exec( cmd );Use javascript for this. I would do it this way....
You can decide with JS if you want tot hide so elements from your browser. Should not be very difficult to implement -
I am wondering if there is any way to add a web browser to your Java application.
I found http://www.javio.com/webwindow/webwindow.html but you have to pay for it in order to be able to use it( except a trial version that expires in a hour :s). But I didn't find another web browser on the internet ... :x
So any idea's / tips ?you can fireup any web-browser from java... just Runtime.exec() it... the trick will be getting it to go to your URL.
-
How to run Executables or .bat files from Java?
Hi!
I need to open a Web Browser from Java App.
Please, help me to do this without calling JNI
-or-
provide me with sample which works with
Runtime.execute() method.
I have done full permission:
grant
permission java.security.AllPermission "","";
};Thank You in advance!To run any command from java code, the method is
Runtime.getRuntime().exec( myCommandString )
Where, myCommandString is something like "/full/pathname/command".
If the pathname contains spaces, e.g. "c:\program files\windows\notepad", then enclose it in quotes within the quoted string. Or pre-tokenize them into elements of an array and call exec(String[] cmd) instead of exec(String cmd).
From JDK1.3 there are two new overloaded Runtime.exec() methods. These allow you to specify starting directory for the child process.
Note, there is a gotcha associated with reading output from commands. When the runtime exec's the process, it passes to it 3 streams, for stdin, stdout, and stderr; the out and err are buffered but the buffer size isn't very big. When your process runs, it reads (if needed) from in, and writes to out and err.
If it doesn't write more than the buffer-size, it can run to completion.
But if it tries to write more data to one or the other stream than the buffer can hold, the write blocks, and your process hangs, waiting for you to empty the buffer so it can write some more.
So after the exec call, get the streams, and read from them in a loop until they both hit end-of-stream (don't block on either one, just read whatever is available from each, each loop iteration).
Then when the streams have ended, call the process.waitFor() method to let it finish dying.
Now, here is a code snippet how you achieve this.
String strCommand = "cmd.exe /c " + strCommand;
boolean bWait = true;
//execute the command
try
Runtime r = Runtime.getRuntime();
Process pr = r.exec(strCommand);
Process pr = r.exec(callAndArgs);
BufferedInputStream bis =new BufferedInputStream(pr.getInputStream ());
int c=0;
/** Outlet for IO for the process **/
while (c!=-1)
c=bis.read();
/**Now wait for the process to get finished **/
if(bWait == true)
pr.waitFor();
pr.destroy();
catch(Exception e)
System.out.println("Could not execute process " + strCommand);
return(false);
Maybe you are looking for
-
Sharing files wirelessly with N80
For some reason I can set up the phone to find the WLAN and can happily browse the net on the handset. But for some reason, selecting "View on home net." or something similar with a media file doesn't do much - it just goes to "searching for devices"
-
Oracle Provider for OLE DB 10.1.0.2.0
Hi, I installed 10g client on my local PC to get access to an ASP application using 10g database. The select always returns no row for a username, therefore, I could not login to the application. But the sqlStatement in SQL*Plus did return a row. Mor
-
HT1677 how do i get tabs in safari?
only got the mac book pro yesterday and cant seem to find the setting
-
WebCenter PS4 and UCM 11gR1-11.1.1.4.0
About to start installing the latest version of WebCenter PS4 and want to link it to an already existing instance of UCM which is "11gR1-11.1.1.4.0-idcprod1-110927T172036 Build 7.3.0.180". Is there any particular problems anyone is aware or should th
-
Error during IdM database creation on Oracle
Hi, We sometimes encounter the following error when creationg IDM database on Oracle (mxmc-install.sh) : *** Updates installed *** Creating language generation procedures mxp_init_ids_onelang mxp_init_ids_lang Warning: Procedure created with compilat