Charlatan
05-04-2007, 07:58 AM
I've been tasked to do some servlet programming and sad to say, I'm just not that good at it. I've run into a sticky problem and am hoping that I can find a smart person who knows how I can accomplish this.
My task involves submitting a query to an SQL database, formatting the results, and displaying them in a nicely formatted web page. I've written a servlet using Java that runs on our JBOSS server (all firsts for me). It all seems pretty simple, and as of now I have it mostly working - there is one issue, however. One of the fields in the database is a string which is a jpeg filename. I'm supposed to display the file iteself in the web page. I can determine an absolute path for the file, which is on a shared volume, but I can't seem to get the image itself displayed in the webpage. For instance:
File name from database: prettyfile.jpg
Result from doing a lookup: /mnt/images/project/prettyfile.jpg
This file definitely exists, and I can examine it from my command shell in Linux. So the path is correct. Seemed to me that I need a way for the web page to suck the image from that file, and that's what I can't figure out.
From what I've been able to determine, I think I need to turn this file path into an URL in order to display it in the web page. So I've been playing around with the java URL class by getting the servlet context and calling getResource on this full path - but that's not working (getResource is returning null when I call it with the absolute path from above).
I know this has *got* to be possible but given that this is my first trip into Java land, servlet land, and JBOSS village, my knowledge is so incomplete that I'm reduced to trying all sorts of things that don't work - and I'm even sure if I need to do this in java, or if I need to modify the servlet so it can access this directory (by modifying the web.xml file?) or what!
Thanks in advance for any help/advice/tips.
My task involves submitting a query to an SQL database, formatting the results, and displaying them in a nicely formatted web page. I've written a servlet using Java that runs on our JBOSS server (all firsts for me). It all seems pretty simple, and as of now I have it mostly working - there is one issue, however. One of the fields in the database is a string which is a jpeg filename. I'm supposed to display the file iteself in the web page. I can determine an absolute path for the file, which is on a shared volume, but I can't seem to get the image itself displayed in the webpage. For instance:
File name from database: prettyfile.jpg
Result from doing a lookup: /mnt/images/project/prettyfile.jpg
This file definitely exists, and I can examine it from my command shell in Linux. So the path is correct. Seemed to me that I need a way for the web page to suck the image from that file, and that's what I can't figure out.
From what I've been able to determine, I think I need to turn this file path into an URL in order to display it in the web page. So I've been playing around with the java URL class by getting the servlet context and calling getResource on this full path - but that's not working (getResource is returning null when I call it with the absolute path from above).
I know this has *got* to be possible but given that this is my first trip into Java land, servlet land, and JBOSS village, my knowledge is so incomplete that I'm reduced to trying all sorts of things that don't work - and I'm even sure if I need to do this in java, or if I need to modify the servlet so it can access this directory (by modifying the web.xml file?) or what!
Thanks in advance for any help/advice/tips.