关于Applet与servlet通讯问题,高手请进,在线等!

onebody 2006-06-19 10:17:12

//servlet端的代码
public class PERTSaveServlet extends HttpServlet {

public void service(HttpServletRequest request, HttpServletResponse response) throws
ServletException, java.io.IOException {
ObjectInputStream inputFromApplet = null;
PERTInfo pertInfo = null;
PrintWriter out = null;
BufferedReader inTest = null;
try {
inputFromApplet = new ObjectInputStream(request.getInputStream());
//pertInfo 是一个序列化的对象
pertInfo = (PERTInfo) inputFromApplet.readObject();
inputFromApplet.close();

if (pertInfo != null) {
...
}


// send back a confirmation message to the applet
out = new PrintWriter(response.getOutputStream());
response.setContentType("text/plain");
out.println("confirmed");
out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}


}
}


//applet端的代码
protected void sendValueToServlet() {
ObjectOutputStream outputToServlet = null;

try {
// connect to the servlet

URL studentDBservlet = new URL(contextPath + "/PERTSaveServlet");
URLConnection servletConnection = studentDBservlet.openConnection();


// inform the connection that we will send output and accept input
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);

// Don't used a cached version of URL connection.
servletConnection.setUseCaches(false);

// Specify the content type that we will send binary data
servletConnection.setRequestProperty("Content-Type", "application/octet-stream");

// send the PERTInfo object to the servlet using serialization
try {

outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());


// serialize the object
outputToServlet.writeObject(pertInfo);


outputToServlet.close();


}
catch (IOException e) {
System.out.println("Error!!!");
}

// now, let's read the response from the servlet.
// this is simply a confirmation string
// readServletResponse(servletConnection);

}
catch (Exception e) {
System.out.println(e.toString());
}

}

为何servlet端接收不到数据?
我是在JBOSS4.0.4+struts环境下调试的,无任何错误提示,APPLET端是正常的,但servlet端好象一点反应都没有?



...全文
97 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyfh 2006-06-19
  • 打赏
  • 举报
回复
关注,我正要做servlet与applet通讯的东东`
liujiwe79 2006-06-19
  • 打赏
  • 举报
回复
是不是发送的地址不对呀?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧