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:
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.