JSP Display Image From File System

The client cannot access the images stored in the file system (outside of your web container) by relative URI. For that you either need to write a servlet as mentioned in this post or if you using Spring MVC, you just need a add a single line of code to your servlet.xml to let Spring take care of everything.
Add the below line to your sevlet.xml


<mvc:resources mapping="/image/**" location="file:///c:/workspace/image/"/>

The above  mapping will be relative to the context of your web application.
For instance, if your application is deployed at http://example.com:8080/myApp then the /image mapping will match when accessed with URL http://example.com:8080/myApp/image/file.jpeg

This is it. This is all you need to do to display images from your local file system in your JSP

See you around
Share on Google+

About Sujit Horakeri

Sujit Horakeri is a game freak just like any other next door guy you would come across. He is a Web Developer by Profession, Game Developer by Choice.
Connect with him on:
    Blogger
    Facebook

2 comments:

  1. I have read your blog its very attractive and impressive. I like it your blog.

    Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

    ReplyDelete