applet向servlet传递对象(是对象而不是简单变量)!在线等待。。。。。。 和传变量有很大区别吗???String型变量,不也就是个String对象吗?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 applet和servlet传递参数使用ObjectOutputStream就行了 我知道你的意思,假如我的applet中有100个字符要传到servlet中,我先自定义一个类FlowView(FlowView view=new FlowView()),然后将这100个字符先写到类里,想在applet中将flowview对象View传到servlet中去。那怎么实现呢? 这些对象必须序列化,给个文档:http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html 我将我的发送applet和接受servlet写出来,你们帮我看看!谢谢!=================sendToServlet=========================void b_actionPerformed(ActionEvent e) { URL url; URLConnection urlc; String chatURL="http://localhost:7001/acceptservlet"; try{ url=new URL(chatURL); urlc=url.openConnection(); urlc.setDoInput(true); urlc.setDoOutput(true); urlc.setUseCaches(false); urlc.setRequestProperty("Content-type","application/octet-stream"); urlc.setAllowUserInteraction(false); urlc.connect(); //写入对象 ObjectOutputStream objectout = new ObjectOutputStream(urlc.getOutputStream()); Vector tmpv = new Vector(); FlowView view=new FlowView(); view.SetName("wjg"); view.SetName1("jlh"); tmpv.add(view); objectout.writeObject(tmpv); objectout.close(); } catch(UnsupportedEncodingException e){ System.out.print("caught a UnsupportedEncodingException"); }catch(MalformedURLException e2){ System.out.print("caught a MalformedURLException"); } catch(IOException e1){ e1.printStackTrace(System.err); } }====================acceptServlet======================= public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/octet-stream"); Vector result = null; ObjectInputStream in=null; try { in = new ObjectInputStream(request.getInputStream()); result = (Vector) in.readObject(); in.close(); } catch (Exception e) { System.out.println("目前还没有对象"); } try { SubmitBean bean=new SubmitBean(); int a=result.size(); for(int i=0;i<a;i++){ FlowView aaa = (FlowView) (result.elementAt(i)); bean.add(aaa);//这是个JAVABEN,功能是向数据库插入数据 } catch (SQLException eee) { System.out.print("无法插入数据库"); } }他就是插不进去内容。 我知道要序列化的,我从servlet向applet发送对象已经弄出来了,但从applet向servlet发送对象却老是不成功!望各位大虾能耐心指点,谢谢! lvyuanfang() ,我先侃侃你提供的文档,然后一定会揭贴的!谢谢! 网上书店系统的技术路线 java 对oracle blob字段的插入都得分2步进行吗? 先插入非blob字段,然后再更新blog字段? 有没有简洁一点的方法? 请大家帮忙看看: 急,怎样把做好的web项目打包成war文件 jsp连access的问题? 请教,关于在线编辑的问题 怎样取HashMap字节附件? 初学JSP应该看什么书好? 传参的问题?参数个数未知 我真的快发疯了,搞了一天了,jsp真难学啊,这是书上的阿 order by的问题 50分,急求一个jsp调用js文件的方法,很容易吧(没错我就是菜鸟)
void b_actionPerformed(ActionEvent e) {
URL url;
URLConnection urlc;
String chatURL="http://localhost:7001/acceptservlet";
try{
url=new URL(chatURL);
urlc=url.openConnection();
urlc.setDoInput(true);
urlc.setDoOutput(true);
urlc.setUseCaches(false);
urlc.setRequestProperty("Content-type","application/octet-stream");
urlc.setAllowUserInteraction(false);
urlc.connect();
//写入对象
ObjectOutputStream objectout = new ObjectOutputStream(urlc.getOutputStream());
Vector tmpv = new Vector();
FlowView view=new FlowView();
view.SetName("wjg");
view.SetName1("jlh");
tmpv.add(view);
objectout.writeObject(tmpv);
objectout.close();
}
catch(UnsupportedEncodingException e){
System.out.print("caught a UnsupportedEncodingException");
}catch(MalformedURLException e2){
System.out.print("caught a MalformedURLException");
}
catch(IOException e1){
e1.printStackTrace(System.err);
}
}
====================acceptServlet=======================
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/octet-stream");
Vector result = null;
ObjectInputStream in=null;
try {
in = new ObjectInputStream(request.getInputStream());
result = (Vector) in.readObject();
in.close();
}
catch (Exception e) {
System.out.println("目前还没有对象");
}
try {
SubmitBean bean=new SubmitBean();
int a=result.size();
for(int i=0;i<a;i++){
FlowView aaa = (FlowView) (result.elementAt(i));
bean.add(aaa);//这是个JAVABEN,功能是向数据库插入数据
}
catch (SQLException eee) {
System.out.print("无法插入数据库");
}
}他就是插不进去内容。