我用两个servlet分别得到节点的数据和链路的数据,applet得到这两个数据之后能画出拓扑图,代码如下
这是得到节点的数据
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myweb?useUnicode=true&characterEncoding=GBK","root","admin");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet result = stmt.executeQuery("select * from physi_node");

CachedRowSetImpl crs = new CachedRowSetImpl();

crs.populate(result);

result.close();

stmt.close();
con.close();

response.setContentType("application/octet-stream");
ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());

oos.writeObject(crs);

oos.close();

}catch(Exception exp){
exp.printStackTrace();
}
}
得到链路的数据
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try{
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myweb?useUnicode=true&characterEncoding=GBK","root","admin");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

ResultSet resultl= stmt.executeQuery("select * from physi_link");

CachedRowSetImpl crsl= new CachedRowSetImpl();

crsl.populate(resultl);

resultl.close();
stmt.close();
con.close();

response.setContentType("application/octet-stream");

ObjectOutputStream oosl = new ObjectOutputStream(response.getOutputStream());

oosl.writeObject(crsl);

oosl.close();
}catch(Exception exp){
exp.printStackTrace();
}

}
applet的代码
public void init() {
// Put your code here
setSize(600, 500);
repaint();
try{
// URL url = new URL("http://localhost:8080/myweb/servlet/servlet/MyServlet");
URL url = new URL(getCodeBase(),"../servlets/MyServlet");
URLConnection urlcon = url.openConnection();
urlcon.connect();
ObjectInputStream ois= new ObjectInputStream(urlcon.getInputStream());
CachedRowSetImpl crs = (CachedRowSetImpl)ois.readObject();
ois.close();

crs.last();
number = crs.getRow();
crs.first();
System.out.println("number+++++"+number);
现在的问题是applet得不到servlet的数据,我怀疑是URL的地址有问题,但是我试验了很多不同的写法,都不行,还请大家帮我想想办法