Sounds to me like the problem is in your toEncodedString() method:
out.writeBytes(toEncodedString(args));
Make sure you're posting in the format:
key1=val1&key2=val2...
You have to be careful NOT to URLEncoder.encode() the '=' and '&'
characters, only the strings.
Vik
-----Original Message-----
From: Nelson <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Saturday, July 29, 2000 3:07 AM
Subject: Applet using POST method to servlet
>Hi,
>
>I am trying to get an applet to send a POST to a servlet. I am not sure
>what I am doing wrong, but the applet does in fact create the parameters
>and then it calsl the servlet and it does get into the doPost() method of
>the servlet. However the servlet only see's null's for the two parameters!
>Here is my code in the applet:
>
> URL url = null;
> try
> {
> //not working
> url = new URL(getDocumentBase(), loginServlet);
>
> Properties args = new Properties();
> args.put("userid", useridTextField.getText());
> args.put("password", passwordPasswordField.getText());
>
> URLConnection urlConnection = url.openConnection();
> urlConnection.setRequestProperty("Content-Type",
>"application/x-www-form-urlencoded");
>
> urlConnection.setDoInput(true);
> urlConnection.setDoOutput(true);
> urlConnection.setUseCaches(false);
>
> DataOutputStream out = new
>DataOutputStream(urlConnection.getOutputStream());
> out.writeBytes(toEncodedString(args));
> System.out.println("userid: " + args.getProperty("userid") +
>"Password: " + args.getProperty("password"));
> out.flush();
> out.close();
> out = null;
>
> DataInputStream in = new
>DataInputStream(urlConnection.getInputStream());
> boolean valid = in.readBoolean();
> System.out.println("Got response: " + new Boolean(valid) );
>
>And here is what i have in the servlet:
>
> //Process the HTTP Post request
> public void doPost(HttpServletRequest request, HttpServletResponse
>response) throws ServletException, IOException
> {
> EnvironmentManager environmentManager =
EnvironmentManager.getInstance();
> UserManager userManager = UserManager.getInstance();
> System.out.println("I am in post");
> // Read the username and password
> String userid = request.getParameter("userid");
> String password = request.getParameter("password");
> System.out.println("Userid: " + userid + "Password: " + password);
> //etc....
>
>I have no idea what is wrong.. I have searched the archives of this mailing
>list - so i have been trying to find a solution. If anyone can point me to
>a solution on the web that I could learn from I would be very greateful.
>
>Thanks
>Nelson
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html