关于Applet与servlet通讯问题,高手请进,在线等!
//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端好象一点反应都没有?