我使用下面的代码将数据发送到servlet
HttpConnection c = (HttpConnection)Connector.open("http://localhost:8585/resposweb/resposweb?action=create_order;deviceside=true");
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("If-Modified-Since", "29 Oct 1999 19:43:31 GMT");
c.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-US");
os = (DataOutputStream)c.openDataOutputStream();
//byte[] res = net.rim.device.api.system.GPRSInfo.getIMEI();
os.writeUTF(ViewItems.isNewOrder());
os.writeUTF(OrderDetails.getOrderDtlAsString());
os.flush();
os.close();
在服务器端,我使用下面的代码从黑莓手机接收数据
DataInputStream in = new DataInputStream((InputStream)request.getInputStream());
String orderType = in.readUTF().trim();
String mobdata = in.readUTF().trim();
但在服务器端,我正处于异常
之下java.io.EOFException
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at com.sath.resposweb.controller.ResPosController.processRequest(ResPosC
ontroller.java:52)
at com.sath.resposweb.controller.ResPosController.doPost(ResPosControlle
r.java:189)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ss(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:45
4)
at java.lang.Thread.run(Unknown Source)
任何人都可以告诉我如何将数据发送到servlet(java)
答案 0 :(得分:1)
使用 HttpConnection.GET 方法在打开连接时通过网址发送数据。