I have written a code of JSP-Servlet. Here is the code:
The request comes in from the HomePage.jsp. The thing is when i run this code from Eclipse it runs fine. But when i run from a browser there is chart.png image is not rendered in the browser! All i get is a browser with a blank page!
Could you please tell me if what i have done is correct.
In all honesty, I'm finding that code and JSP really, really difficult to read and understand--it looks like a complete nightmare to maintain and debug, for several reasons. I'm not even sure where to start, so I'll skip that part.
My first guess would be that your image tag is essentially empty. The second guess would be that you're trying to serve an image that isn't even in the web application context using an image tag.
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
posted
0
My image tag is something like this
IMG SRC="E:\\Softwares\\chart.jpg" WIDTH="600" HEIGHT="400" BORDER="0" USEMAP="#chart"
Somehow the text are not turning up in the code tag or even the quote tag!
I have tried running it in both IE and Firefox and they both display nothing! Also could you please mention some pointers to make the JSP a little bit more readable!
Praveen mourya Kumar
Greenhorn
Joined: Oct 14, 2008
Posts: 16
posted
0
Somnath Mallick wrote:My image tag is something like this
IMG SRC="E:\\Softwares\\chart.jpg" WIDTH="600" HEIGHT="400" BORDER="0" USEMAP="#chart"
Somehow the text are not turning up in the code tag or even the quote tag!
I have tried running it in both IE and Firefox and they both display nothing! Also could you please mention some pointers to make the JSP a little bit more readable!
Hi Somnath,
Can you please try to keep all the images under Application Context Root. I mean to say, make one folder(say images) near your WEB-INF. And try to access all the images from there.
SCJP 1.6..
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
posted
0
I am trying to create the file in the application context root. But i am running into some problems. I have changed the image file to be created to something like..
I want the image to be created in the images folder under WebContent folder (WebContent/images/chart.jpg). But the file is not being generated there and hence is not being rendered in browser.
That will try to create the image in directory under the root directory of a Unix system.
If you're trying to create the image in the web application's directory you'll need to get the real path.
IMO, this is a bad idea: dynamically-created images shouldn't be created in the web app context, as they might be removed during a redeploy, etc. Create them in, and serve them from, a directory that's guaranteed to exist, and guaranteed to not be destroyed. Images outside of the application context can be served via a servlet (or whatever back end technology you're using).
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
posted
0
That's the problem... When I try to use a fixed path on my local system, it is working through eclipse, but not when i directly run the servlet through browser.
All i get is a blank page! I have attached a screen shot of my eclipse and mozilla. Please see!
The fixed path used is:
and i am rendering it like:
SRC="E:\\Softwares\\chart.jpg" WIDTH="1000" HEIGHT="600" BORDER="0" USEMAP="#chart"
You need to serve images outside the application context with a servlet (or whatever back-end technology you're using).
Somnath Mallick
Ranch Hand
Joined: Mar 04, 2009
Posts: 471
posted
0
There is no back-end application as such. This code just reads an excel sheet from a particular file path and a properties file and generates a graph. That's all.
Could you please kindly show me an example?
Somnath Mallick wrote:There is no back-end application as such.
I disagree, since you posted servlet code.
Images outside the application context should be served with a servlet--if you search the web for "image servlet" or something similar you'll find many, many examples.