Return-Path: Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 36524 invoked from network); 4 Apr 2000 15:34:25 -0000 Received: from interlock2.lexmark.com (192.146.101.10) by locus.apache.org with SMTP; 4 Apr 2000 15:34:25 -0000 Received: by interlock2.lexmark.com id LAA28770 (InterLock SMTP Gateway 4.2 for tomcat-dev@jakarta.apache.org); Tue, 4 Apr 2000 11:34:23 -0400 Message-Id: <200004041534.LAA28770@interlock2.lexmark.com> Received: by interlock2.lexmark.com (Protected-side Proxy Mail Agent-1); Tue, 4 Apr 2000 11:34:23 -0400 X-Lotus-Fromdomain: LEXMARK@LEXMTA From: nathank@lexmark.com To: tomcat-dev@jakarta.apache.org Date: Tue, 4 Apr 2000 11:32:58 -0400 Subject: Classloder for a JSP is differnet than a servlet Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Rating: locus.apache.org 1.6.2 0/1000/N I have a concern that the ClassLoader for a JSP page is different than for a Servlet. This can cause different behavior between running with a JSP and precompiling with JSPC and running the JSP as a Servlet. The specific problem I ran into is not being able to load a resource bundle with ResourceBundle.getResource() from a JSP because the JSP ClassLoader ( org.apache.jasper.runtime.JspLoader) can't find the resources in WEB-INF\classes. It does work if you call ResourceBundle.getResource() from a bean or a Servlet because they use the org.apache.tomcat.loader.AdaptiveClassLoader ClassLoader. I couldn't find in the JSP/Servlet specs if a JSP should be able to load resources from the WEB-INF\classes or WEB-INF\lib directories. Is this a bug in Tomcat? Nathan Klemperer ---------------------- Forwarded by Nathan Klemperer/Lex/Lexmark on 04/04/2000 11:25 AM --------------------------- Nathan_Klemperer.LEXMARK@lexmta01.notes.lexmark.com on 03/30/2000 01:13:50 PM Please respond to tomcat-dev%jakarta.apache.org@interlock.lexmark.com To: tomcat-dev%jakarta.apache.org@interlock.lexmark.com cc: (bcc: Nathan Klemperer/Lex/Lexmark) Subject: RE: ResourceBundle.getBundle() throws MissingResourceException in JSP I think I know why you can't load a ResourceBundle from a JSP page. When a JSP is compiled by Jasper, it is loaded using the org.apache.jasper.runtime.JspLoader ClassLoader. This ClassLoader does not implement getResourceAsStream(), which is used by ResourceBundle.getBundle(). Beans and Servlets are loaded by org.apache.tomcat.loader.AdaptiveClassLoader which does implement getResourceAsStream(). Also, if you precompile your JSP using JSPC, it works because it is now a servlet and loaded by org.apache.tomcat.loader.AdaptiveClassLoader. Is this a bug? I think that JSP's should behave the same as precompiled JSP's. Nathan Klemperer jfrederic.clere%fujitsu.siemens.es@interlock.lexmark.com on 03/30/2000 12:15:28 PM Please respond to tomcat-dev%jakarta.apache.org@interlock.lexmark.com To: tomcat-dev%jakarta.apache.org@interlock.lexmark.com cc: (bcc: Nathan Klemperer/Lex/Lexmark) Subject: RE: ResourceBundle.getBundle() throws MissingResourceException in JSP jakarta-tomcat/src/share/org/apache/tomcat/loader/AdaptiveClassLoader.java.. . I get a problem in jserv and it dispairs after a fixe (not from me!): --- ./src/java/org/apache/java/lang/AdaptiveClassLoader.java.org Wed Dec 8 21:33:25 1999 +++ ./src/java/org/apache/java/lang/AdaptiveClassLoader.java Fri Feb 4 13:05:33 2000 @@ -656,18 +656,28 @@ */ private InputStream loadResourceFromZipfile(File file, String name) { ZipFile zipfile = null; + InputStream resourceStream = null; try { zipfile = new ZipFile(file); ZipEntry entry = zipfile.getEntry(name); if (entry != null) { - return zipfile.getInputStream(entry); + long length = entry.getSize(); + resourceStream = zipfile.getInputStream(entry); + byte[] data = loadBytesFromStream(resourceStream, (int)length); + return new ByteArrayInputStream(data); } else { return null; } } catch(IOException e) { return null; } finally { + if ( resourceStream != null ) { + try { + resourceStream.close(); + } catch ( IOException ignored ) { + } + } if ( zipfile != null ) { try { zipfile.close(); Any way the code we use looks bad (the close closes the InputStream... do not it?). <> > -----Original Message----- > From: nathank@lexmark.com [SMTP:nathank@lexmark.com] > Sent: Thursday, March 30, 2000 5:39 PM > To: tomcat-dev@jakarta.apache.org > Subject: ResourceBundle.getBundle() throws MissingResourceException > in JSP > > When I try to get a ResourceBundle from a JSP, I get a > MissingResourceException. > But if I do it in a Bean called from the JSP, it works. It also works > from a > servlet. I have the properties file in the WEB-INF\classes directory. > Anyone > know why? I think it has something to do with the ClassLoader. I'm using > the > 20000327 build of Tomcat > > Nathan Klemperer > > > Here is the JSP file: > > <%@ page language="java" %> > <%@ page import="java.util.*" %> > > > > > Test > > > > <% > try > { > out.println("

Try to get ResourceBundle from > ResourceBundle.getBundle()"); > > ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); > out.println("

Success: " + rb.getString("helloworld.title")); > } > catch (MissingResourceException e) > { > out.println("

Failed: " + e); > } > > try > { > out.println("

Try to get ResourceBundle from Bean"); > > ResourceBundle rb = new RB("LocalStrings").rb; > out.println("

Success: " + rb.getString("helloworld.title")); > } > catch (MissingResourceException e) > { > out.println("

Failed: " + e); > } > %> > > > Here is the Bean: > > public class RB > { > public java.util.ResourceBundle rb; > > public RB(String name) > { > rb = java.util.ResourceBundle.getBundle(name); > } > } > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org