我的applet中发送数据部分如下:
try{
URLConnection connect;
String urlText ="http://192.168.102.177:8080/ecommerce/testservlet"; //define url from getDocumentBase() or getCodeBase() since you can only access the same server the applet was loaded from without signing the applet.
URL url = new URL(urlText);
connect = url.openConnection();
connect.setDoOutput(true);
connect.setDoInput(true);
connect.setRequestProperty("Content-Type","text/plain");
OutputStream out = connect.getOutputStream();
InputStream in = connect.getInputStream();
//out.writeUTF();
byte[] b = "ifassfsa sadfasdfam wood".getBytes();
out.write(b);
byte[] b1 = new byte[6];
in.read(b1);
String str = new String(b1);
System.out.println("get from server:"+str);
out.close();
}catch(Exception e){
System.out.println("wrong:"+e.toString());
}在servlet中接收数据如下:
ServletInputStream in =req.getInputStream();
ServletOutputStream out = res.getOutputStream();
//Object bb = req.getAttribute("abc");
byte[] b = new byte[5];
in.read(b);
//in.reate
out.write("woodpeng is good".getBytes());
//out.println("the bytes bb we get:"+bb.toString());
out.println("the bytes b we get:"+new String(b));
System.out.println("the bytes we get:"+new String(b));
System.out.println("contect type:"+req.getContentType());
out.print("receive user message:");结果是在applet中,可以收到servlet中返回的数据,但是servlet却收不到applet发送的byte[],各位看看是什么问题???
try{
URLConnection connect;
String urlText ="http://192.168.102.177:8080/ecommerce/testservlet"; //define url from getDocumentBase() or getCodeBase() since you can only access the same server the applet was loaded from without signing the applet.
URL url = new URL(urlText);
connect = url.openConnection();
connect.setDoOutput(true);
connect.setDoInput(true);
connect.setRequestProperty("Content-Type","text/plain");
OutputStream out = connect.getOutputStream();
InputStream in = connect.getInputStream();
//out.writeUTF();
byte[] b = "ifassfsa sadfasdfam wood".getBytes();
out.write(b);
byte[] b1 = new byte[6];
in.read(b1);
String str = new String(b1);
System.out.println("get from server:"+str);
out.close();
}catch(Exception e){
System.out.println("wrong:"+e.toString());
}在servlet中接收数据如下:
ServletInputStream in =req.getInputStream();
ServletOutputStream out = res.getOutputStream();
//Object bb = req.getAttribute("abc");
byte[] b = new byte[5];
in.read(b);
//in.reate
out.write("woodpeng is good".getBytes());
//out.println("the bytes bb we get:"+bb.toString());
out.println("the bytes b we get:"+new String(b));
System.out.println("the bytes we get:"+new String(b));
System.out.println("contect type:"+req.getContentType());
out.print("receive user message:");结果是在applet中,可以收到servlet中返回的数据,但是servlet却收不到applet发送的byte[],各位看看是什么问题???
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货