wood burning stoves 2.0*
The moose likes Java in General and the fly likes Open firefox window and redirect to a url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Open firefox window and redirect to a url" Watch "Open firefox window and redirect to a url" New topic
Author

Open firefox window and redirect to a url

Teena Mariam
Greenhorn

Joined: Jul 14, 2008
Posts: 24

Hello,

Is there any possibility to open firefox(version independent) in Linux using Java (Without javascript)?
The program should open firefox with the url : http://www.gmail.com and it should automatically populate the user id and password and should log in. We can provide the user id and password in a text file.

Thanks in advace,
Teena
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

java.lang.Runtime OR java.lang.Process


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
campbell@queeg:~$ firefox --h
Usage: /usr/lib/firefox-3.0.13/firefox [ options ... ] [URL]
where options include:

X11 options
--display=DISPLAY X display to use
--sync Make X calls synchronous
--no-xshm Don't use X shared memory extension
--xim-preedit=STYLE
--xim-status=STYLE
--g-fatal-warnings Make all warnings fatal

Mozilla options
-height <value> Set height of startup window to <value>.
-h or -help Print this message.
-width <value> Set width of startup window to <value>.
-v or -version Print Firefox version.
-P <profile> Start with <profile>.
-ProfileManager Start with ProfileManager.
-no-remote Open new instance, not a new window in running instance.
-UILocale <locale> Start with <locale> resources as UI Locale.
-safe-mode Disables extensions and themes for this session.
-jsconsole Open the Error console.
campbell@queeg:~$
campbell@queeg:~$ firefox http://www.javaranch.com
campbell@queeg:~$
. . . and a JavaRanch tab opened. I don't know whether it is possible to provide a user name too. Beware: if you put your password in an unencrypted file, it is at risk of hacking.

You would need to start a Process with Runtime.exec(). Before doing that, be sure to read Michael Daconta's article "when Runtime.exec() won't".
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Campbell Ritchie wrote:You would need to start a Process with Runtime.exec(). Before doing that, be sure to read Michael Daconta's article "when Runtime.exec() won't".

Thanks Campbell, I didn't know that !
Adam Michalik
Ranch Hand

Joined: Feb 18, 2008
Posts: 128
If the site you are trying to open supports parameters via HTML GET, you can build the URL with them (eg. http://www.gmail.com?user=somename&password=somepassword). However, I don't thing that GMail supports such a thing (especially sending the password in the URL). But the user can switch on a "remember me" option in GMail so that whenever the site is opened, the user logged in automatically. This is done by Firefox and cookies, so no effort on Java side (but the user will have to log in manually for the first time and enable the "remember me" function).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Sagar Rohankar wrote:Thanks Campbell, I didn't know that !
You're welcome Lots of people think it is easy to use Runtime.exec() but the Daconta article shows it is quite difficult.
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Teena:

You might consider looking into using Selenium. Selenium is made for this kind of thing (web testing), and has a Java API (along with a number of other languages). It is also widely used. You can check it out here.

John.
sarath gopal
Greenhorn

Joined: Aug 19, 2009
Posts: 3

Hi Teena,

did you try Java Desktop api..you can use it to launch browser without any difficulty
use this link for intro
Using Desktop API
 
 
subject: Open firefox window and redirect to a url
 
Similar Threads
How to invalidate a session in one browser when the same user login from any other browser?
Double authorizing
Double authentication
Double authentication
How to invalidate a session in one browser when the same user login from any other browser?