File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Autologin a website Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Autologin a website" Watch "Autologin a website" New topic

Autologin a website

khaja mohideen

Joined: May 20, 2011
Posts: 12
Hi all,

I am really thankful if anyone guide me.

I have a link when i press the link it goes to a website and automatically fll the username password fields and automatically submit the button and move to logged page of that website

i use windows.navigate function,but i don't know how to take the id of username and password fields of navigate page.

Thank you all.
Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 208

I've always used HTTP POST and passed a string containing all the parameters needed for logging in. For example, the POST string to login to JavaRanch is (identifying info removed)

Try out an http debugger (I used Fiddler just now) to find your POST string.

Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
khaja mohideen

Joined: May 20, 2011
Posts: 12
Thank you for your reply ,
I use the post method to submit and pass the username and password in hidden boxes
,but it doesn't receive and put it in the texbox fields of navigate page.

the username and password feilds of navigate page is null

Tina Smith
Ranch Hand

Joined: Jul 21, 2011
Posts: 208

Using the post method allows you to skip the filling in of the username and password into the textboxes altogether.

When you normally login (via a browser) to a webpage, the sequence of events is something like this:
1. Go to url
2. Fill in the login/password boxes
3. Press login
4. Browser sends a POST message containing the login/password you just filled in.

I'm suggesting you skip steps 2 and 3 since all you need is the output of those steps (which you already know) and just go straight to the POST message.

What you would do is something like this:
Create an http message to go to the url of your login page.
Set the message type to POST.
Add the login string (which will be formatted similar to &username=<username>&password=<password> but may have extra arguments (that's why I recommend an http debugger).
Send the message.

I've never actually done this in Java, only Visual Basic, so I'm not sure what the classes to use in Java are.
khaja mohideen

Joined: May 20, 2011
Posts: 12
Really thankful for your reply,but i have a code like this

function login() {

<BODY onLoad="login()">
<FORM NAME="form" METHOD="post">
<input type="hidden" id="login" name="loginname" value="abc" />
<input " type="hidden" id="password" name="passwordfield" value="abc"/>
<INPUT TYPE="hidden" VALUE="enter" />

it goes to but not fill the username and password field of

any clues
thank you
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Of course not. You can't set the form values on another site.

If it's condoned (and only if), you should post to the form action, not the form itself.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Autologin a website
jQuery in Action, 3rd edition