You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by "Julien, Timothy" <TJ...@Bluestone.com> on 2001/03/22 01:15:51 UTC

another bug in Jasper - incorrect File.separator

Still in the endeavor of running Jasper in another container....

When making calls in ParserController.getReader() to
ServletContext.getResourceAsStream() (through JspCompilationContext), the
String that is passed in is file.toString() (where file denotes the jsp to
be translated/compiled).  The problem with that call is that File.toString()
calls File.getPath(), which replaces '/' with File.separator - which on
Windows is '\'.  However, calls to ServletContext.getResourceAsStream() must
begin with '/', per the servlet 2.2 javadocs.  Hence, getResourceAsStream()
returns null.

I've included the fix:

in org.apache.jasper.compiler.ParserController:

private InputStreamReader getReader(File file, String encoding,
					String absFileName)
	throws FileNotFoundException, JasperException
{
        InputStream in;
        InputStreamReader reader;

	  try {
	    if (ctxt == null) {
		in = new FileInputStream(file);
		reader = new InputStreamReader(in, encoding);
	    } else {
		//String fileName = ctxt.getRealPath(file.toString());

               // TDJ
               // changed file.toString( ) ->
               // absFileName
               // ServletContext.getResourceAsStream( ) requires
               // url slashes ( '/' ), not platform specific slashes
		in = ctxt.getResourceAsStream(absFileName);
		if (in == null) {
		    throw new FileNotFoundException(absFileName);
		}
		reader = new InputStreamReader(in, encoding);
	    }
	    return reader;
	   } catch (UnsupportedEncodingException ex) {
	     throw new JasperException(
                Constants.getString("jsp.error.unsupported.encoding",
				    new Object[]{encoding}));
	     }
}

Tim Julien
HP middleware