You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Gladwell, Ricardo X -ND" <Ri...@dig.com> on 2003/01/21 17:00:48 UTC

Opening Files Outside Context

Hi All,

I have written a JavaBean accessed from a JSP page in Tomcat 4.1 that
opens a file to read from. However, when I open the file using the
FileInputStream constructor I get a FileNotFoundException. This method
works outside of Tomat on the same machine - the file exists, the path
is correct even if it is on a networked drive. 

I assume this is a security feature - the file is outside the webapps
directory. What I would like to know is there anyway of allowing Tomcat
web applications to accessing files outside their container, either
through changing settings in the web.xml or server.xml files or through
the Tomcat admin tool?

TIA...

-- 
Ricardo Gladwell, Java Developer
WD Internet Group, Engineering
[t] (020) 8222 2723
[m] (07734) 813 187 

Stack Trace:

java.io.FileNotFoundException: h:\projects\adtagger\xml\config.xml (The
system cannot find the path specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(FileInputStream.java:103)
	at java.io.FileInputStream.<init>(FileInputStream.java:66)
	at
com.dig.rgladwel.adtagger.ConfigBean.setConfigFile(ConfigBean.java:100)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:324)
	at
org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSuppo
rt.java:172)
	at
org.apache.jsp.index_jsp._jspx_meth_c_set_0(index_jsp.java:116)
	at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
	at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
va:204)
	at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
	at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:247)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:193)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:260)
	at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:191)
	at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:241
5)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:180)
	at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
	at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherVa
lve.java:170)
	at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:641)
	at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:172)
	at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:641)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:174)
	at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.i
nvokeNext(StandardPipeline.java:643)
	at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:4
80)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
	at
org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
	at
org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:261)
	at
org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:360)
	at
org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:632)
	at
org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:
590)
	at
org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:707)
	at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool
.java:530)
	at java.lang.Thread.run(Thread.java:536)

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Opening Files Outside Context

Posted by Dan Tran <da...@hotmail.com>.
I have no problem opening file outsite my context,

Make sure you have the file path setup correctly

-D
----- Original Message -----
From: "Erik Price" <ep...@ptc.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Tuesday, January 21, 2003 9:47 AM
Subject: Re: Opening Files Outside Context


>
>
> Gladwell, Ricardo X -ND wrote:
> > Hi All,
> >
> > I have written a JavaBean accessed from a JSP page in Tomcat 4.1 that
> > opens a file to read from. However, when I open the file using the
> > FileInputStream constructor I get a FileNotFoundException. This method
> > works outside of Tomat on the same machine - the file exists, the path
> > is correct even if it is on a networked drive.
> >
> > I assume this is a security feature - the file is outside the webapps
> > directory. What I would like to know is there anyway of allowing Tomcat
> > web applications to accessing files outside their container, either
> > through changing settings in the web.xml or server.xml files or through
> > the Tomcat admin tool?
>
> Did you already try "getServletContext().getResourceAsStream()"?
>
> What I have learned (yesterday) is that it is best to register an
> external file in the web.xml as a ContextParameter and then use
> getServletContext().getInitParameter() to refer to the file.  This
> forces whoever is deploying your app to make sure that there is in fact
> a resource available (and provides a means to change the path of that
> resource without going into the code to do so).  Just some advice, I
> suspect you can use getResourceAsStream() without consulting the
> ServletContext for the resource.
>
>
>
> Erik
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Opening Files Outside Context

Posted by Erik Price <ep...@ptc.com>.

Gladwell, Ricardo X -ND wrote:
> Hi All,
> 
> I have written a JavaBean accessed from a JSP page in Tomcat 4.1 that
> opens a file to read from. However, when I open the file using the
> FileInputStream constructor I get a FileNotFoundException. This method
> works outside of Tomat on the same machine - the file exists, the path
> is correct even if it is on a networked drive. 
> 
> I assume this is a security feature - the file is outside the webapps
> directory. What I would like to know is there anyway of allowing Tomcat
> web applications to accessing files outside their container, either
> through changing settings in the web.xml or server.xml files or through
> the Tomcat admin tool?

Did you already try "getServletContext().getResourceAsStream()"?

What I have learned (yesterday) is that it is best to register an 
external file in the web.xml as a ContextParameter and then use 
getServletContext().getInitParameter() to refer to the file.  This 
forces whoever is deploying your app to make sure that there is in fact 
a resource available (and provides a means to change the path of that 
resource without going into the code to do so).  Just some advice, I 
suspect you can use getResourceAsStream() without consulting the 
ServletContext for the resource.



Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>