dcsimg
Posting to a form login page
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   James_Owen
Posted On:   Tuesday, September 4, 2001 12:29 PM


I'm trying to post username/password information to JSP form login page using the following method



			
URLConnection con = url.openConnection();
PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
out.print("j_username=uname&j_password=password&action=Submit Logon");
out.flush();
out.close();



I looks a though the JSP never receives the message because it does not give back a response, redirect me to an error page, or allow access to the secure servlet. Any thoughts on this? Thanks.

Re: Posting to a form login page

Posted By:   John_Wang  
Posted On:   Wednesday, September 5, 2001 08:31 AM

You forget to do something important:

In this case, you need do POST operation,

So, you should setup URLConnection with

code:

con.setDoOutput();



Only you do this can browser send out your POST message!!



Good luck.

Re: Posting to a form login page

Posted By:   Anonymous  
Posted On:   Tuesday, September 4, 2001 03:58 PM

I think you need to add before obtaining the stream this statement:

con..setDoOutput(true);


I would check also the way you're 'post'ing values: the "Submit Logon" will not be recognized because is not encoded. Try changing to:

out.print("j_username=uname&j_password=password&action=" + URLEncode.encode("Submit Logon"));


Regards.

Re: Posting to a form login page

Posted By:   Christopher_Pickslay  
Posted On:   Tuesday, September 4, 2001 02:58 PM

It's not clear to me exactly what you're trying to do, but I see 2 issues:


  1. The correct URL encoding for your action parameter would be Submit+Logon, not Submit Logon
  2. Maybe you just excluded this from your code sample, but are you checking getResponseCode() and getInputStream() on your URL connection to see what the response was? How are you determining that you didn't get a response?
About | Sitemap | Contact