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

onebody onebody 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

//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端好象一点反应都没有?



...全文
评论 2
收藏 已收藏
分享
返回顶部
onebody
Java SE 62,620 成员 307,251 内容