j2me如何向servlet传参数(因参数不止一个,需用post方法)

zhj8727 2009-03-30 09:46:20
手机部分:
......
//因参数不止一个,也不统一,需用post方法
htpConn = (HttpConnection)Connector.open("http://localhost:8080/MyServlet/UpdateDBServlet");//得到连接对象
htpConn.setRequestMethod(HttpConnection.POST);//GET是缺省设置,可以省略
htpConn.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0" );
htpConn.setRequestProperty("Content-Language", "en-CA" );
htpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String str = "name=zhj";
htpConn.setRequestProperty("Content-Length",Integer.toString( str.length()));

OutputStream out = htpConn.openOutputStream();
out.write(str.getBytes());
out.flush();
.......
servlet部分:
response.setContentType("text/html; charset=gb2312");//设置返回的类型
ServletOutputStream out = response.getOutputStream();//得到输出流
DataOutputStream dos = new DataOutputStream(out);
String name = null;
name = request.getParameter("name");
if ( null != name){
dos.writeUTF(name);
}
else {
dos.writeUTF("null");
}
dos.writeUTF("这是测试结果doPost");
问题:
servlet无法受到手机传来的参数name,
执行完name = request.getParameter("name");
name为null.



...全文
158 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kb_element 2009-09-28
  • 打赏
  • 举报
回复
少了out.close(); 抄别人的也要研究下 是否抄完整了才好 ..
yanhan0615 2009-03-30
  • 打赏
  • 举报
回复
楼主,你用的是post方法,取值的时候要用stream取
InputStream in=response.getInputStream();
in.read()

这样就对了
zhj8727 2009-03-30
  • 打赏
  • 举报
回复
很急!!!请大家帮忙看下参数为什么传不到servlet中。
kf156 2009-03-30
  • 打赏
  • 举报
回复
没做过,上网查了下,说是将flush()去了。
zhj8727 2009-03-30
  • 打赏
  • 举报
回复
代码是参考网上的帖子
zhj8727 2009-03-30
  • 打赏
  • 举报
回复
打印name 后是null么?
是的
zhaoyb0319 2009-03-30
  • 打赏
  • 举报
回复
打印name 后是null么?
zhj8727 2009-03-30
  • 打赏
  • 举报
回复
难道没人做过吗???

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧