• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28438
104
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic