This week's book giveaways are in the Jython/Python and Object-Oriented programming forums. We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line! See this thread and this one for details.
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.
posted 17 years ago
Still having problems with this. If someone could at least tell me whether this is possible or not that would be great.
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.
posted 17 years ago
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.