有没有解决使用objectOutputStreamhere
和sendRedirect()
!之间的冲突的解决方案?
private void writeObjectStream(HttpServletRequest request,
HttpServletResponse response) {
getQueryFromAttribute(request);
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(response.getOutputStream());
oos.writeObject(appInfo);
oos.writeObject(serviceInfo);
oos.writeObject(queriesMap);
response.reset();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtil.closeQuietly(oos);
}
}
我在这里称它为writeObjectStream
writeObjectStream(request, response);
try {
response.sendRedirect(response.encodeRedirectURL(appInfo.getUrl()));
} catch (IOException e) {
e.printStackTrace();
}
我为这个问题尝试了另一种解决方案,如下所示:
private void writeObjectStream(HttpServletRequest request,
HttpServletResponse response) {
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(response.getOutputStream());
oos.writeChars("x");
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtil.closeQuietly(oos, ois);
}
}
的呼唤writeObjectStream
:
....
response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
response.setHeader("Location", "www.sample.com");
response.setHeader("Content-Length", "" + 500);
writeObjectStream(request, response);
return true;
}
这个解决方案的问题是 java.io.EOFException
当我尝试做时它会在服务器端 启动ois = new ObjectInputStream(request.getInputStream());