jsp:include with a servlet returns IOException: Stream Closed
- From: jstorta <js@xxxxxxxxxx>
- Date: Thu, 29 Nov 2007 12:18:37 -0800 (PST)
I have a servlet which returns a list of links to CSS files.
I am trying to include this servlet in the HEAD section of the jsp
page so that the proper style sheets get loaded. I know the servlet
works because I can run it directly from the URL with no problems.
However, when I put this in the jsp file
<jsp:include page="/CSSLoader" flush="true" >
<jsp:param name="style" value="default" />
</jsp:include>
I get this when I load the page
java.io.IOException: Stream closed
Prior to using a servlet, the code was just in another jsp page as a
scriptlet. I included the jsp page the exact same way as I am
including the servlet, and it worked just fine.
It seems to me that when the servlet calls the PrintWriter, the stream
is already closed so it fails. This wasn't the case when the code was
a scriptlet in a jsp file.
The question is, how can I include this servlet in my page before the
stream is closed?
Any guidance would be appreciated. For reference, I have pasted the
relevant method from the servlet below.
Thanks.
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
try {
String style = request.getParameter( "style" );
String browserType = request.getHeader("User-Agent").toLowerCase();
String browserPath = "msie";
if ( browserType.indexOf("msie") != -1 ) {
browserPath = "msie";
}
else if ( browserType.indexOf("gecko") != -1 ) {
browserPath = "gecko";
}
File dir = new File("/cssrepository/" + browserPath + "/" +
style );
String linkStringPrefix = new String("<LINK REL=STYLE*** HREF='/
myapp/include/css/" + browserPath + "/" + style + "/");
String linkStringSuffix = "' TYPE='text/css'>";
String[] children = dir.list();
if( children == null ) {
System.out.println( "Either the directory does not exist or it is
empty\n" );
}
else {
for( int i=0; i<children.length; i++ ) {
String filename = children[i];
if( filename.endsWith( "css" ) ) {
out.print( linkStringPrefix );
out.print( filename );
out.println( linkStringSuffix );
}
}
}
} finally {
out.close();
}
}
.
- Prev by Date: Java J2EE Openings in Phoenix, AZ, Client Will Relocate
- Next by Date: Re: Array initialisation
- Previous by thread: Java J2EE Openings in Phoenix, AZ, Client Will Relocate
- Next by thread: Switching from Non-Blocking to Blocking IO
- Index(es):