JSP代碼:反序列化從JSP頁面獲得的Java對象?
<%
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutputStream output = new ObjectOutputStream(stream);
output.writeObject(new BigDecimal("111"));
output.flush();
output.close();
response.getOutputStream().write(stream.toByteArray());
out.clear();
out = pageContext.pushBody();
%>
在客戶端代碼,(反應是org.apache.http.HttpResponse
一個對象)
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
byte[] buff = new byte[1024];
is.read(buff);
ByteArrayInputStream bi = new ByteArrayInputStream(buff);
ObjectInputStream oi = new ObjectInputStream(bi);
我得到異常:
Exception in thread "main" java.io.StreamCorruptedException: invalid stream header: 3C68746D
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:783)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
您使用HTTP或其它協議當然 – shinynewbike 2011-06-14 09:37:30
,HTTP ...... – 2011-06-14 10:27:48
任何理由來使用,而不是一個簡單的servlet和jsp? – artbristol 2011-06-14 12:04:06