• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem passing parameters on url from MIDlet to servlet

 
john gorman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the J2me wireless toolkit to create an application to connect to a database from a mobile phone. I have written a servlet that reads in the values from a login midlet in the doGet(). The MIDlet is connecting to the servlet (using jswdk_1.0.1) and the servlet is getting the two parameter names but not their associated values. (I have done a getParameterNames() and printed it out to screen). If I hard-code values for userId and pasword the servlet reads them.

I have 2 textfields - usernameInput and passwordInput and the code is as follows:

userId = usernameInput.getString();
password = passwordInput.getString();
String url = "http://127.0.0.1:8080/servlet/DatabaseServlet?userId="+ userId +"&password="+ password ;
try{
//mc is a HttpConnection object with request set to GET
conn = mc.makeConnection(url);
conn.setRequestProperty("CONTENT-TYPE", "application/x-www-form-encoded"); }
catch(IOException e) {}
Can anyone offer a suggestion as to what I am doing wrong?

Thanking you in anticipation.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since hardcoded userId and password would work, the problem is most likely to be with your TextField. You could trim() both strings to make sure that leading and trailing white spaces are removed.
To debug, maybe you should print the entire url from the MIDlet before you make the connection.
 
john gorman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where would I print out the URL - on the server terminal or the MIDlet emulator and how can I do this?
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic