I am new to jsp,when I try to invoke a jsp page by some parameters named cId and passWord,I getting this error,The code I have been trying is given below,I have already gone
This is a JSP with scriplet which is converted into a Servlet file. You dont need to call explicitly the response object. If you need to see how a compiled JSP looks like when its deployed , search (Google) how to look for the compiled class(Servlet generated out of JSP) on the server. Since you have already called the method on the response a second invocation is Illegal on the response object
You shouldn't try and do this inside a JSP. The JSP will already have obtained an output stream to write it's output. You need to use a servlet to return your XML.
When you call response.getOutputStream, it is conflicting with the fact that the JSP (which will be compiled into a servlet) already obtained an output stream. This is why it is resulting in the IllegalStateException.
Throws:IllegalStateException
- if the getWriter
method has been called on this response .
This means that you can call either getWriter()
or getOutputStream()
methods.
Now in JSP (and eventually in compiled servlet), there is an implicit variable defined called out
. This is nothing but an instance of PrintWriter
class. This means that on the response object, getWriter()
is already called and hence on calling getOutputStream()
you get IllegalStateException
Now as solution for this problem, as some people have pointed out, move this code into a servlet where you have full control and use the outputstream the way you want.