You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Tim Funk <fu...@joedog.org> on 2004/09/08 19:49:39 UTC
JspServlet.serviceJspFile() getResourceAsStream vs getResource
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.
-Tim
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: JspServlet.serviceJspFile() getResourceAsStream vs getResource
Posted by Jan Luehe <Ja...@Sun.COM>.
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