RE: Invoking a servlet from JSP
I have a self-contained servlet that returns a single value. I am trying to include the output of this servlet in-line on an HTML/JSP page. When I try to invoke the servlet using the following JSP INCLUDE tag, the page bombs with Exception #500 (java.lang.IllegalStateException: Writer is already being used for this request): jsp:include page="/servlet/TestServlet" flush="true" jsp:param name="type" value="apples" / /jsp:include But when I use the JSP FORWARD tag, the servlet and page work perfectly, except for the fact that the page returned contains only the output of the servlet (as expected): jsp:forward page="/servlet/TestServlet" jsp:param name="type" value="apples" / /jsp:forward How can I accomplish what I need? BTW, I am using Tomcat 3.2.1. One solution I can think of is using the second option have the servlet forward back to the referrer jsp passing the answer value(s). The reason the include doesn't work is because in your servlet there is a call to getWriter() while the jsp page still has a handle on the JSPWriter. Another option might be replacing your servlet with a bean but I'm not sure about that. --- Michael Wentzel Software Developer Software As We Think http://www.aswethink.com mailto:[EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: Invoking a servlet from JSP
turn your servlet into a taglib or a javabean. I think you are using the wrong approach using a servlet like this. --Angus "Robert E. Baker" wrote: I have a self-contained servlet that returns a single value. I am trying to include the output of this servlet in-line on an HTML/JSP page. When I try to invoke the servlet using the following JSP INCLUDE tag, the page bombs with Exception #500 (java.lang.IllegalStateException: Writer is already being used for this request): jsp:include page="/servlet/TestServlet" flush="true" jsp:param name="type" value="apples" / /jsp:include But when I use the JSP FORWARD tag, the servlet and page work perfectly, except for the fact that the page returned contains only the output of the servlet (as expected): jsp:forward page="/servlet/TestServlet" jsp:param name="type" value="apples" / /jsp:forward How can I accomplish what I need? BTW, I am using Tomcat 3.2.1. Thanks, Bob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
RE: Invoking a servlet from JSP
You can try using javax.servlet.RequestDispatcher or in the worst case you can open up a java.net.HttpURLConnection to the servlet and grab the returned data. I'm pretty sure that there is a struts taglib that will do the latter too. Troy -Original Message- From: Robert E. Baker [mailto:[EMAIL PROTECTED]] Sent: Monday, January 22, 2001 5:46 PM To: [EMAIL PROTECTED] Subject: Invoking a servlet from JSP I have a self-contained servlet that returns a single value. I am trying to include the output of this servlet in-line on an HTML/JSP page. When I try to invoke the servlet using the following JSP INCLUDE tag, the page bombs with Exception #500 (java.lang.IllegalStateException: Writer is already being used for this request): jsp:include page="/servlet/TestServlet" flush="true" jsp:param name="type" value="apples" / /jsp:include But when I use the JSP FORWARD tag, the servlet and page work perfectly, except for the fact that the page returned contains only the output of the servlet (as expected): jsp:forward page="/servlet/TestServlet" jsp:param name="type" value="apples" / /jsp:forward How can I accomplish what I need? BTW, I am using Tomcat 3.2.1. Thanks, Bob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: Invoking a servlet from JSP
Do you have an example of this, or can you point me in the right direction? Bob -- From: Troy Landers [EMAIL PROTECTED] To: "'[EMAIL PROTECTED]'" [EMAIL PROTECTED] Subject: Re: Invoking a servlet from JSP Date: Tue, 23 Jan 2001 09:57:15 -0600 You can try using javax.servlet.RequestDispatcher or in the worst case you can open up a java.net.HttpURLConnection to the servlet and grab the returned data. I'm pretty sure that there is a struts taglib that will do the latter too. Troy -Original Message- From: Robert E. Baker [mailto:[EMAIL PROTECTED]] Sent: Monday, January 22, 2001 5:46 PM To: [EMAIL PROTECTED] Subject: Invoking a servlet from JSP I have a self-contained servlet that returns a single value. I am trying to include the output of this servlet in-line on an HTML/JSP page. When I try to invoke the servlet using the following JSP INCLUDE tag, the page bombs with Exception #500 (java.lang.IllegalStateException: Writer is already being used for this request): jsp:include page="/servlet/TestServlet" flush="true" jsp:param name="type" value="apples" / /jsp:include But when I use the JSP FORWARD tag, the servlet and page work perfectly, except for the fact that the page returned contains only the output of the servlet (as expected): jsp:forward page="/servlet/TestServlet" jsp:param name="type" value="apples" / /jsp:forward How can I accomplish what I need? BTW, I am using Tomcat 3.2.1. Thanks, Bob - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: Invoking a servlet from JSP
"Robert E. Baker" wrote: I have a self-contained servlet that returns a single value. I am trying to include the output of this servlet in-line on an HTML/JSP page. When I try to invoke the servlet using the following JSP INCLUDE tag, the page bombs with Exception #500 (java.lang.IllegalStateException: Writer is already being used for this request): jsp:include page="/servlet/TestServlet" flush="true" jsp:param name="type" value="apples" / /jsp:include How does your servlet create its output? If the servlet calls response.getWriter(), this should work fine because it will use the same output writer that the JSP page is using. You should only hit this exception if your servlet tries to call response.getOutputStream() instead. Craig McClanahan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: Invoking a servlet from JSP
Michael Wentzel wrote: Do you have an example of this, or can you point me in the right direction? The tomcat implementation is in src/org/apache/tomcat/core/RequestDispatcherImpl.java. Depending on what you need passed to the servlet(as long as you don't need the entire HttpSession for some reason), I still think that a bean is a better solution. FYI, the JSP engine uses a RequestDispatcher to implement the jsp:include and jsp:forward tags. Doing it yourself is not going to help matters if the includer and includee are trying to do two different kinds out output (by calling getWriter() versus getOutputStream()). Using a jsp:include is a perfectly reasonable solution if you want the output of the included servlet to be copied to the output page -- it's basically the same thing as doing server-side includes on static web pages. A bean or tag will work better when you want to process the output created by the called object before writing it to the response. IMHO --- Michael Wentzel Craig McClanahan - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]