image from jar to web page?

A

Andrew Thompson

How can I get an image from a jar file into
a web page?

I am using JSP to haul the goodies out of my
PhySci software suite and onto the net as web
pages, thus far I have turned PToE (Periodic Table)
into a crude 113 page website at..
http://1point1c.physci.org/chemistry/

Next up is Pocket Planet, containing basic information
on the planets.

The problem is, I cannot figure how to grab images
out of a jar archive and put them into a web page.

[ Short of presenting them in an applet, which I want
to avoid (I want these sites to be usable by people
with 'no java') ]

Can somebody point me to a tutorial or give me
some good search terms that will put me on the
right path?

TIA
 
J

J.P.Jarolim

Hi.

Do you want to keep the images in the jar?
You can use winzip (just copy and rename the jar to zip) and put the images
somewhere the webserver can reach them.
But there surely is a possibility to use them out of the jar anyway.

If you want to use them out-of-the-jar i'll take a look.

greets,

J.P.Jarolim
 
A

Andrew Thompson

...
Do you want to keep the images in the jar?

Yep, sure do!

I need be confident that the web pages will
update if the jar changes. ..Not that that would
be a major problem for the planets, but if I were
to add another package containing the moons,
the 'moons.jar' may change on a regular basis.

[ I could, conceivably unpack the jar before
upload, but that seems like a terribly
inefficient 'solution'.. ]

Alternatively, I could have the files extracted
from the .jar and reproduced on the server
as uncompressed images the first time they
are called, but I do not want to create a
proliferation of files on the server.

Thanks for your suggestion though. :)
 
J

J.P.Jarolim

Hi.

So you should have a look at
Object.getClass().getClassLoader().getResource()
Thats the way to get a file located in the same jar as the executed
program - so there should be a way to get files out of another jar around
imho.

Additionally you can create a servlet which reads the raw file content and
serves it to the browser.
You should change the mime-return-type of the servlet to image/jpeg or
whatever you want to serve.

greets,

J.P.Jarolim


Andrew said:
..
Do you want to keep the images in the jar?

Yep, sure do!

I need be confident that the web pages will
update if the jar changes. ..Not that that would
be a major problem for the planets, but if I were
to add another package containing the moons,
the 'moons.jar' may change on a regular basis.

[ I could, conceivably unpack the jar before
upload, but that seems like a terribly
inefficient 'solution'.. ]

Alternatively, I could have the files extracted
from the .jar and reproduced on the server
as uncompressed images the first time they
are called, but I do not want to create a
proliferation of files on the server.

Thanks for your suggestion though. :)
 
A

Andrew Thompson

.....
So you should have a look at
Object.getClass().getClassLoader().getResource()
Thats the way to get a file located in the same jar as the executed
program - so there should be a way to get files out of another jar around
imho.

Additionally you can create a servlet which reads the raw file content and
serves it to the browser.
You should change the mime-return-type of the servlet to image/jpeg or
whatever you want to serve.

:) Sorry! It's one of those, 'what to put in,
what to leave out' things - where apparently
I misjudged on two counts..

a) Forgot to mention that I also want to
create new images (eg graphs of data)
and present them in pages as well.
(So occasionally the images will not exist till
moments before they are delivered to the
web surfer)

b) _Not_ using the image/jpeg thing.
First, because I wish to put the images
into pages containing other, textual data,
and AFAIU that content type is only
suitable for a single image.
Second, because I thought I'd read
somewhere that it had been deprecated(??)
(not sure whether by Sun or W3C)

Perhaps I should also point out that actually
getting the images is not a problem, I have already
created applets that present zip/jar files as
directory structures that can display html (complete
with images) in a (otherwise horrendously poor)
JEditorPane. e.g.
http://www.physci.org/applet/Ziplet.htm
 
J

J.P.Jarolim

Hi.
a) Forgot to mention that I also want to
create new images (eg graphs of data)
and present them in pages as well.
(So occasionally the images will not exist till
moments before they are delivered to the
web surfer)

So - whats exactly your problem?
What's the question about images in a jar - apparently you have to create
and deliver your images on the fly?
Please explain your problem again in full detail.
b) _Not_ using the image/jpeg thing.
First, because I wish to put the images
into pages containing other, textual data,
and AFAIU that content type is only
suitable for a single image.
Second, because I thought I'd read
somewhere that it had been deprecated(??)
(not sure whether by Sun or W3C)

Same thing - Please explain again, what you want to do.
Btw. you have to treat every image you create as a single image.
Jpeg isn't deprecated either and gif is a legal problem (in europe at
least).
Perhaps I should also point out that actually
getting the images is not a problem, I have already
created applets that present zip/jar files as
directory structures that can display html (complete
with images) in a (otherwise horrendously poor)
JEditorPane. e.g.

So - what is your problem here??
Please learn to state your problem so someone can actually answer it.
Btw. your applet doesn't work with ie6 and the standard ie-java-plugin.

greets,

J.P.Jarolim
 
T

Tim Tyler

J.P.Jarolim said:
So - what is your problem here??
Please learn to state your problem so someone can actually answer it.

I think he explained why a Java solution was unsatisfactory:

``Short of presenting them in an applet, which I want to avoid
(I want these sites to be usable by people with 'no java')''
Btw. your applet doesn't work with ie6 and the standard ie-java-plugin.

The MS JVM? Hardly suprising - since it uses a JEditorPane.
 
A

Andrew Thompson

Tim Tyler said:
If your clients use Mozilla/Firebird, you can just go:

jar:http://mandala.co.uk/imagesinjars/test.jar!/test.gif

Way cool! Now if they could only make IE that way.. :-(

In fact, just for the hell of it, I tried it in IE.
'Invalid Syntax Error' ...hmmm.
As opposed to a ..'Valid Syntax Error'? ;-)
For a more portable solution you will probably have to extract
them into temporary files on the server.

Sounds like the best solution.
I am not sure how to do that, but I'll look into it.

[ Last time I dealt with temporary files was back in
the Amiga days - I am not even clear whether 'temporary'
files assume the programmer will delete*, or whether it
is part of the undelying OS.
* For that matter - I don't even know whether 'delete'
is the correct term. ]

Thanks Tim.

Thanks as well to J.P., for his/her time and effort.
 
A

Andrew Thompson

Andrew Thompson said:
....
I am not sure how to do that, but I'll look into it.

Now that I go back and RTFM I spot
File.createTempFile().

[ Like ...duh! ]

Solves the entire problem as far as I can see.
I'll write some code out over the next week
and give it a go.. :)
 
T

Tim Tyler

Andrew Thompson said:
Now that I go back and RTFM I spot
File.createTempFile().

Note that:

The files don't get deleted until the JVM exits;
The files don't get deleted unless they are closed;
 
A

Andrew Thompson

Tim Tyler said:
....
Note that:

The files don't get deleted until the JVM exits;

Wait, ..the _server_ JVM exiting?
Is that not a rare and _bad_ thing?

Unfortunately the JavaDocs were a bit sketchy
on the finer details.
The files don't get deleted unless they are closed;

OK, that part is no problem..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top