This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes getting output from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "getting output from servlet" Watch "getting output from servlet" New topic

getting output from servlet

Peter Guillebaud
Ranch Hand

Joined: Jul 11, 2001
Posts: 57
Hi there,
As I understand it the servlet is meant to do the business logic - but how can you get the output, say of reading a file, from a servlet to be displayed in a jsp page?
thanks in advance
Fred Abbot
Ranch Hand

Joined: Jun 01, 2000
Posts: 300
servlets can output HTML
Peter Guillebaud
Ranch Hand

Joined: Jul 11, 2001
Posts: 57
sure, but I want the output to be displayed as part of a jsp page that has other stuff on it unrelated to this servlets' function...?
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
The <jsp:include/> action includes the results of page request (dynamically, as opposed to the static <@% include file="..." %> directive), so this should work for you. Try something like :
<jsp:include page="/servlet/MyServlet"/>
Let us know how you get on!

Simon Brown
Co-author of Professional JSP 2nd Edition
Peter Guillebaud
Ranch Hand

Joined: Jul 11, 2001
Posts: 57
Hi Simon,
Thanks very nuch for your reply. I am having problems with this I'm afraid... I get an error message as follows:
org.apache.jasper.JasperException: Invalid jsp:include tag
at org.apache.jasper.compiler.IncludeGenerator.(
at org.apache.jasper.compiler.JspParseEventListener.handleInclude(
at org.apache.jasper.compiler.DelegatingListener.handleInclude(
at org.apache.jasper.compiler.Parser$Include.accept(
at org.apache.jasper.compiler.Parser.parse(
at org.apache.jasper.compiler.Parser.parse(
at org.apache.jasper.compiler.Parser.parse(
at org.apache.jasper.compiler.Compiler.compile(
at org.apache.jasper.runtime.JspServlet.loadJSP(
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.loadIfNecessary(
at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(
at org.apache.jasper.runtime.JspServlet.serviceJspFile(
at org.apache.jasper.runtime.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.tomcat.core.ServletWrapper.handleRequest(
at org.apache.tomcat.core.ContextManager.service(
at org.apache.tomcat.service.connector.Ajp12ConnectionHandler.processConnection(

Is this likely to be a problem with the way tomcat is set up?
Jeff Sunder
Ranch Hand

Joined: Jun 26, 2001
Posts: 47
You need to add the following attribute in the jsp include:
<jsp:include page="/servlet/MyServlet"/ flush="true">
I agree. Here's the link:
subject: getting output from servlet
It's not a secret anymore!