Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java html show img src is system path

 
G.Sathish kumar
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

i need to display image in html page which there in system path i mean outside of application path

calling file : /tomcat/webapps/student/jsp/first.jsp

image placed in : /images/img.gif so image is not there in tomcat folder itself

i used html is not working but same when i try with windows is working so any one please help me ASAP because i need to close the issue.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
G.Sathish kumar wrote:Hi

i need to display image in html page which there in system path i mean outside of application path

calling file : /tomcat/webapps/student/jsp/first.jsp

image placed in : /images/img.gif so image is not there in tomcat folder itself

i used html is not working but same when i try with windows is working so any one please help me ASAP because i need to close the issue.


A web server is not a file server. So to get a webserver to return an image file's contents, you have to provide a URL mapping and a transport mechanism.

In most webapps, the URL mapping is the built-in one that says that if the app server receives a URL and it can't determine anything else to do with it, it will take the part of the URL that follows the webapp context and precedes the query parameters and use it to locate a file-type resource relative to the base of the WAR (unless the root directory of that path is "WEB-INF"). Once the resource is located, the system will then open it and copy its contents to the response data stream.

Since you want to use an external location for shared resources, and there's no built-in mechanism that does that, you'd need to define a servlet that does the same thing as the built-in server function but knows to look in your "/images" directory instead of in an images directory in your WAR. It's a very simple servlet, since all it does is construct a file path, open the file at that path location (if there is a file there!), then copies it to the response writer stream. Probably 20 lines of Java code. You may even find one already written if you do a little web searching, since this is actually a fairly common thing to do.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic