servet向applet传递对象数组失败。请哪位高人指点一下。通信代码如下:
servlet:
URL url;
URLConnection urlc;
String queryString = "http://127.0.0.1:8080/graphics/servlet/DataServlet";
try {
url = new URL(queryString);
urlc = url.openConnection();
// urlc.setDefaultUseCaches(false);
urlc.setUseCaches(false);
urlc.setDoInput(true);
urlc.setDoOutput(true);
urlc.connect();
//ObjectOutputStream out = new ObjectOutputStream(urlc.getOutputStream());
ObjectInputStream in = new ObjectInputStream(urlc.getInputStream());
FDJAry = (Fadianji[]) in.readObject();//FDJAry 是一个对象数组,每个元素是一个Fadianji类型的对象。
applet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;public class DataServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException {
super.init();
}
public void doGet(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException{
String sql="";
rp.setContentType("application/x-java-serialized-object");
try {
String url="jdbc:odbc:hzdw";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,"","");
。
。
。//中间的代码与通信无关
ObjectOutputStream out=new ObjectOutputStream(rp.getOutputStream());
out.writeObject(FDJAry);//FDJAry是一个对象数组,从数据库中取数构建的
out.flush();
out.close();
}catch (SQLException ex) {
ex.printStackTrace();
System.out.println("Can't Connect The database!!");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Servlet IO Problem!!");
} catch (java.lang.Exception ex1) {
ex1.printStackTrace();
System.out.println("ClassNotFound!!");
}
}
public void doPost(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException{
doGet(rq,rp);
}
}
applet接收不到数据,请哪位高手指点一下。
servlet:
URL url;
URLConnection urlc;
String queryString = "http://127.0.0.1:8080/graphics/servlet/DataServlet";
try {
url = new URL(queryString);
urlc = url.openConnection();
// urlc.setDefaultUseCaches(false);
urlc.setUseCaches(false);
urlc.setDoInput(true);
urlc.setDoOutput(true);
urlc.connect();
//ObjectOutputStream out = new ObjectOutputStream(urlc.getOutputStream());
ObjectInputStream in = new ObjectInputStream(urlc.getInputStream());
FDJAry = (Fadianji[]) in.readObject();//FDJAry 是一个对象数组,每个元素是一个Fadianji类型的对象。
applet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;
import java.util.*;public class DataServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException {
super.init();
}
public void doGet(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException{
String sql="";
rp.setContentType("application/x-java-serialized-object");
try {
String url="jdbc:odbc:hzdw";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,"","");
。
。
。//中间的代码与通信无关
ObjectOutputStream out=new ObjectOutputStream(rp.getOutputStream());
out.writeObject(FDJAry);//FDJAry是一个对象数组,从数据库中取数构建的
out.flush();
out.close();
}catch (SQLException ex) {
ex.printStackTrace();
System.out.println("Can't Connect The database!!");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Servlet IO Problem!!");
} catch (java.lang.Exception ex1) {
ex1.printStackTrace();
System.out.println("ClassNotFound!!");
}
}
public void doPost(HttpServletRequest rq,HttpServletResponse rp) throws ServletException,IOException{
doGet(rq,rp);
}
}
applet接收不到数据,请哪位高手指点一下。
上面那个是applet中的代码,下面那个是servlet