This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have one problem. I have one web url htpp://127.0.0.1:8080/UserLogin.jsp Now I have to acees this url though java code not from the web browser. When I am accessing this page through HttpURLConnection class, It is ok, but can any body tell me how I can give user name and password through code for this page UserLogin.jsp.
Are you using form-based authentication? Send the user name and password as request parameters like this example. If you are using HTTP based authentication, use the Authenticator class as described here.
If login from a browser does POST on a form, you can simulate that nicely with your URLConnection. Set DoInput and DoOutput true, get the output stream from the connection and write your form content. Don't forget to flush and close the stream.
Here's what I write to log on my Wiki ... the form has two hidden fields and the userid & password entry fields:
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35243
7
posted
0
See this entry of the Applet FAQ, which describes how to do it. In this regard, applets and applications are identical.
If you have idea where the form of login.jsp is hitting then you can fake out the login process and there is no harm in this as you are making a tool not the browser.If you know where the login form sumbits like /cool/verify and username variable is user and password is pass then you can create the url like /cool/verify?user=<userName>&pass=<password> with the url try creating the HTTPURLConnection , similar is the process .The only thing is that user=<userName>&pass=<password> will be in the body and you have to set the header set-content-length header.