4

In .net you have the ability to Response.End() in any context you want. Is there similar functionality in Java/JSP?

Thanks,

Sam

2 Answers2

3

In my experience you have to do the following:

out.flush(); // Send out whatever hasn't been sent out yet.
out.close(); // Close the stream. Future calls will fail.
return; // Return from the JSP servelet handler.

NOTE:
This will not work inside a function because you'll just end up returning from the function but not from the JSP servelet handler (which I'm assuming is your intention).

grammar31
  • 2,000
  • 1
  • 12
  • 17
0

You could try

servletResponse.getOutputStream().close();

Not quite sure if that will have odd side effects though, in case the server needs to send any data after your content...

Javadoc

matt b
  • 138,234
  • 66
  • 282
  • 345
  • When I do something like what I am doing below, nothing gets written to the browser, I would think that 'TEST' would get written and thats the behavior I am trying to achieve, Any suggestions? <% out.println("TEST"); response.getOutputStream().close(); out.println("TEST2"); –  Feb 20 '09 at 20:29
  • "out" isn't the same thing as response.getOutputStream() -- have you tried out.close()? – Jacob Mattison Feb 20 '09 at 20:51