Java Web Start 访问Servlet
ty713 2008-07-29 02:20:57 我用applet开发了一个客户端程序,使用JWS发布,动态配置jnlp,启动没有任何问题,
但是启动的客户端始终访问不了指定的servlet,无法完成与服务器的交互,
如果在eclipse里面直接run java applet启动是能够访问到指定的servlet的
请问各位这是为什么?
代码如下:
URLConnection con = null;
try {
URL urlServlet = new URL(strUrl); //strUrl即指定的servlet
con = urlServlet.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty(
"Content-Type",
"application/x-java-serialized-object");
} catch (MalformedURLException e) {
con = null;
} catch (IOException e) {
con = null;
}
}
if (con == null) {
return;
}
OutputStream outstream = null;
ObjectOutputStream oos = null;
try {
outstream = con.getOutputStream();
oos = new ObjectOutputStream(outstream);
oos.writeObject(input); //input要传递到servlet的参数
oos.flush();
oos.close();
} catch (IOException e) {
} finally {
if( oos != null ){
try { oos.close(); } catch(Exception e){ }
}
if( outstream != null ){
try { outstream.close(); } catch(Exception e){ }
}
}