我有一个ActionScript文件将XML发送到我的servlet。 我只在输出上获得空数组。谁知道我究竟做错了什么? 输出是:
java.io.StreamCorruptedException:无效的流标头 at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:764) 在java.io.ObjectInputStream。(ObjectInputStream.java:277) at myDungeonAccessor.myDungeonAccessorServlet.doPost(myDungeonAccessorServlet.java:82)
package myDungeonAccessor;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
System.out.println("HEADERS: " + request.getHeaderNames());
ObjectInputStream in = new ObjectInputStream(request.getInputStream());
System.out.println(in);
ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());
} catch(Exception e) {
e.printStackTrace();
}
异常
答案 0 :(得分:1)
System.out.println()
写入stdout(通常最终在服务器日志和/或IDE控制台中,如果有的话),而不是响应。改为写response.getWriter()
。
尽管如此,我建议使用XStream将完整的Javabeans写入XML without pains。
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
new XStream().toXML(bean, response.getOutputStream());