Piotrek
Piotrek

Reputation: 130

How to link to files on local disk from html in JSF 2.0 app

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

Upvotes: 1

Views: 1344

Answers (2)

BalusC
BalusC

Reputation: 1109072

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" />

Upvotes: 1

Sazzadur Rahaman
Sazzadur Rahaman

Reputation: 7126

"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.

Upvotes: 0

Related Questions