I've been developed an application in j2me that send parameters (via POST) to a
servlet. But these parameters don't have being recognized by this one (servlet).
J2me code:
HttpConnection http = null;
OutputStream os = null;
InputStream in = null;
boolean ret = false;
String url = "
http://localhost:8080/corej2me1/Teste.do";
try {
http = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
http.setRequestMethod(HttpConnection.POST);
http.setRequestProperty("User-Agent",
"Profile/MIDP-1.0 Confirguration/CLDC-1.0");
http.setRequestProperty("Content-Language", "en-CA");
// send input
String str = "name=182016";
http.setRequestProperty("Content-Length", "" + str.length());
http.setRequestProperty("Connection", "close");
http.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
os = http.openOutputStream();
byte postmsg[] = str.getBytes();
for (int i = 0; i < postmsg.length; i++) {
os.write(postmsg[i]);
}
os.flush();
os.close();
SERVLET CODE:
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// InputStream s = req.getInputStream();
// BufferedReader bis = new BufferedReader(new InputStreamReader(s));
//
// String str;
// while ((str = bis.readLine()) != null) {
// System.out.println(str);
// }
Enumeration enume = req.getHeaderNames();
while (enume.hasMoreElements()) {
String str2 = enume.nextElement().toString();
System.out.println(str2 + " : " + req.getHeader(str2));
}
//
// Enumeration enume2 = req.getParameterNames();
// while(enume2.hasMoreElements()) {
// String str2 = enume2.nextElement().toString();
// System.out.println(str + " : " + req.getParameter(str));
// }
//
System.out.println(req.getParameter("name"));
}
can anybody help me to solve this problem?
Thanks a lot.