tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Luehe <Jan.Lu...@Sun.COM>
Subject Re: JspServlet.serviceJspFile() getResourceAsStream vs getResource
Date Wed, 08 Sep 2004 20:03:52 GMT
Hi Tim,

Tim Funk wrote:
> This is just a nit, but in JspServlet.serviceJspFile() there is ...
>             synchronized(this) {
>                 wrapper = (JspServletWrapper) rctxt.getWrapper(jspUri);
>                 if (wrapper == null) {
>                     // Check if the requested JSP page exists, to avoid
>                     // creating unnecessary directories and files.
>                     InputStream resourceStream =
>                         context.getResourceAsStream(jspUri);
>                     if (resourceStream == null) {
>                         
> response.sendError(HttpServletResponse.SC_NOT_FOUND,
>                                            jspUri);
>                         return;
>                     } else {
>                         try {
>                             resourceStream.close();
>                         } catch(IOException e) { /* ignore */ }
>                     }
>                     ...
>                 }
>             }
> 
> Is there any reason we are getting the stream instead of checking for a 
> null URL, for example:
> 
>             synchronized(this) {
>                 wrapper = (JspServletWrapper) rctxt.getWrapper(jspUri);
>                 if (wrapper == null) {
>                     // Check if the requested JSP page exists, to avoid
>                     // creating unnecessary directories and files.
>                     if (null==context.getResource(jspUri)) {
>                         
> response.sendError(HttpServletResponse.SC_NOT_FOUND,
>                                            jspUri);
>                         return;
>                     }
>                     ...
>                 }
>             }
> 
> This way the existence of the file is checked instead of opening it.

Good point! There must have been a reason for using getResourceAsStream()
in the past, but I agree it is no longer necessary and just
committed your proposed patch.


Jan





---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message