1

I use tomcat 7.0 and eclispe WTP plugin. I can't reference to file on my local disk. <h:graphicImage value="C:/tmp/someFile.png"/>

I tried to resolve it by adding in location C:\Program Files (x86)\apache-tomcat-7.0.32\webapps directory tmp/ and use <h:graphicImage value="/tmp/someFile.png"/>

I tried also add from eclipse to tomcat file: server.xml <Context docBase="C:/tmp" path="/tmp" />

<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

  <Context docBase="myProjectName" path="/myProjectName" reloadable="true" source="org.eclipse.jst.jee.server:myProjectName"/>
  <Context docBase="C:/tmp" path="/tmp" /></Host>

and reference to file in the same way <h:graphicImage value="/tmp/someFile.png"/>

In result I have HTTP Status 404. description The requested resource is not available.

How Can I resolve it ? Thanks

Piotrek
  • 130
  • 1
  • 7

2 Answers2

1

The <h:graphicImage> automatically prepends the context path of the current webapp in the URL. If you'd have looked at the generated HTML output and/or the HTTP traffic monitor in webbrowser's builtin webdeveloper toolset, you'd have noticed it.

Just use plain HTML <img> element instead.

<img src="/tmp/someFile.png" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

"webapp" directory serves as the root directory of your application when you deploy it (ideal practice). So if you use path (url) "/tmp/someFile.png" to access file someFile.png, then you must put the file in "/src/main/webapp/tmp/someFile.png" and after deployment put the contents of "webapp" into root directory of your application.

So basically just make sure that "tmp" is in your applications root directory.

If you want to use filesystem. You can see this answer here.

Community
  • 1
  • 1
Sazzadur Rahaman
  • 6,938
  • 1
  • 30
  • 52
  • But in tmp directory I want to store a lot of users files and I think it should be separate from aplication root directory. – Piotrek Nov 17 '12 at 18:27