我試圖在Applet中獲取簡單的用戶詳細信息(名稱,電話號碼,性別(選項框)),並在JSP中顯示詳細信息。我將所有三個詳細信息一個HashMap並將其發送到輸出流中。 Applet代碼如下。從Applet發送數據到servlet時的EOFException
try
{
userUrl = "http://localhost:8080/AppletTest/display.jsp";
/* In the web.xml file I have mapped display.jsp to the Servlet */
testServlet = new URL(userUrl.toString());
servletConnection = testServlet.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setRequestProperty("Content-Type","application/octet-stream");
ObjectOutputStream oos1 = new ObjectOutputStream(servletConnection.getOutputStream());
/* DataMap is the HashMap Containing values */
oos1.writeObject(dataMap);
oos1.flush();
oos1.close();
// Thread.currentThread().sleep(5000);
}
catch(Exception ie)
{
ie.printStackTrace();
}
// Finally call servlet by going to that page.
getAppletContext().showDocument(userUrl, "_self");
雖然上一個servlet我剛剛拿到的HashMap並將其轉發給一個JSP頁面來顯示。
try
{
System.out.println("In Servlet");
ObjectInputStream inputFromApplet = new ObjectInputStream(request.getInputStream());
HashMap<String,String> receievedData = (HashMap<String,String>) inputFromApplet.readObject();
request.setAttribute("dataMap",receievedData);
request.getRequestDispatcher("display1.jsp").forward(request, response);
inputFromApplet.close();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
作爲問評價在問題here所述的SYSOUT(「在Servlet的」)被打印。但拋出異常
In Servlet
SEVERE: Servlet.service() for servlet jsp threw exception java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2280)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream. java:2749)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:779)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
at org.apache.jsp.display1_jsp._jspService(display1_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
我在做什麼錯。請幫忙。
謝謝SimoneGianni。是的,這是接縫問題。但我不清楚如何使用兩個servlet(或使用一個servlet和可選的參數)。如果你能詳細說明,這將是非常有用的。 – anthoon