• Post Reply Bookmark Topic Watch Topic
  • New Topic

does the write() method of the OutputStream comit the respose before this call to forward()?  RSS feed

 
nforchu cheka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
response.setContentType(“application/jar”);
ServletContext ctx = getServletContext();
InputStream is = ctx.getResourceAsStream(“bookCode.jar”);
int read = 0;
byte[] bytes = new byte[1024];
OutputStream os = response.getOutputStream();
while ((read = is.read(bytes)) != -1) {
os.write(bytes, 0, read);
}

RequestDispatcher view = request.getRequestDispatcher(“result.jsp”);
view.forward(request, response);
os.close();
}


i can't understand why i have an error with this. because i know calling os.flush() before dispatching the request will give me an IllegalStateException. but i don' know if write commits the response too.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem isn't that you are writing to the servlet's output stream. The problem is that you are forwarding to a JSP after you finish. Don't do that. You're sending a copy of a jar file as the response; forwarding to a JSP just adds on some HTML at the end which would only make a mess anyway. Don't do that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!