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

Reply via email to