I have a servlet (MnNav), it extracts a data from a database into a bean. The servlet then forwards to a jsp page (MnNav.jsp) that lists the extracted data. This works fine stand alone. That is, if you just type http://localhost/servlet/MnNav However, when I make a new jsp page (Include.jsp)and include the servlet (MnNav) like this, <html> <%@ page contentType="text/html" %> <jsp:include page="/servlet/MnNav" flush="true"/> </html> and then type http://localhost/Include.jsp , only the html tags are returned. I placed out.println in both the servlet (MnNav) and MnNav.jsp to see if they execute. Executed standalone both run. Executed from the Include.jsp page only the servlet seems to run. I know you can include the output of a servlet but if the servlet (which produced not output) then forwards to a jsp page (creating output) will this output get included ?? Thanks.
Bruno Collins
Greenhorn
Joined: Nov 30, 2001
Posts: 19
posted
0
Still having problems with this. If someone could at least tell me whether this is possible or not that would be great.
Roy Ben Ami
Ranch Hand
Joined: Jan 13, 2002
Posts: 732
posted
0
try using the <%@include file %> instead. the <jsp:include> only includes the OUTPUT of the servlet. if it prosuces no output then why use it? witht the @ include directive you are actually copy paste the whole servlet to the jsp page.
Bruno Collins
Greenhorn
Joined: Nov 30, 2001
Posts: 19
posted
0
I know the servlet doesn't produce anything directly, but the servlet forwards to a jsp page that DOES produce the output. The servlet is gathering info from a databases that is then used in the jsp page. Am I missing something.
One problem you might run into by doing it this way, is an IllegalState exception. If your JSP page produces a whole bunch of output, and then 'includes' a servlet that actually 'forwards' to another page for output, then this is a problem.
You can't output (beyond the output buffer size) and then forward to another page, or you get that exception. If you output within the buffer size and then forward, all the output from that first JSP is gone, and you only get the output from forwarding. (which is why you say "only the servlet seems to run")
forward should be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws an IllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: JSP Include (output of servlet forwarding to JSP)