You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Micael <ca...@harbornet.com> on 2003/01/24 22:14:39 UTC
Image References From JSP Pages inside WEB-INF
How do you reference images, or other resources, from JSP pages inside
WEB-INF if you want the images inside WEB-INF too?
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank you
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Image References From JSP Pages inside WEB-INF
Posted by Max Cooper <ma...@maxcooper.com>.
Remember that requests for images are separate from the requests for pages.
It works kind of like this dialog between the browser and server:
browser: please send /index.html
server: okay, here it is:
<html>
<head></head>
<body><img src="/images/bmx_mullet.jpg"></body>
</html>
browser: (oh! I need an image, I better ask for it...) please send
/images/bmx_mullet.jpg
server: okay, here it is: 001010100100101010101001010...
Because it works this way, putting images in /WEB-INF will prevent the
server from being able to serve them normally. Unless you have a
well-thought-out reason to put them there, it is probably not a good idea.
If you have images that you want people to be authenticated to see, you can
simply put them in a directory that is protected via container-managed
security, as defined in your web.xml. Then let the server do its job serving
the images. Your images are secured, and no custom servlets or actions are
required.
If the images are files and just need more fine-grained security, a Filter
might be appropriate. However, be careful not to create an image dumping
ground that will end up full of stale images. Backup and sharing among
clustered servers can be an issue also. If an image only needs to be seen
once, writing it to a file might not be a very good idea. A servlet or an
Action to stream the image data back to the user might be more appropriate.
That way you don't have to manage files, which can be problematic in many
ways. For example, if you have an action that shows a page with employee
info including a dynamically-generated graph of their salary history over
time, your browser/server dialog might look like this:
browser: please send /viewEmployee.do?id=100
server: okay, here it is: (server invokes Struts Action to show employee
page)
<html>
<head></head>
<body>
Employee Number: 100<br>
Name: Kid Rock<br>
Salary History:<br>
<img src="/servlet/employeeSalaryHistory.gif?id=100">
</body>
</html>
browser: please send /servlet/employeeSalaryHistory.gif?id=100
server: okay, here it is: (server runs servlet mapped to
/servlet/employeeSalaryHistory.gif that dynamically creates an employee
history salary chart image and streams the data back in the response)
001010100100101010101001010...
Another case where it can be useful to use an action or servlet to stream
the data back is when you allow users to upload images and you want to store
them as BLOBs in the db rather than the filesystem for easy backups,
clusters, or whatever reason. There are no files on the disk, so you need to
write out img tags that will ask your servlet/Action for the image they want
and then have the servlet/Action load the image from the db and stream the
data back.
When streaming data from an action or servlet, be sure to set the MIME type
of the response appropriately. Using a mapping that looks like an image
filename (/something.jpg)can also be helpful to browser when it needs to
figure out what kind of file it is going to get back. However, it probably
wouldn't be a good idea to send an GIF in response to a request for
/servlet/showImage.jpg, so only do that if you know the type. Or make the
mapping /showImage/* and write out img tags with something like
src="/showImage/2259.gif" to match the real type of the file. The "filename"
from the URL can help, but it is most important to call
response.setContentType() with the right MIME type string. Content length
should be set as well.
In the case where it is okay for the browser to cache the images (uploaded
product image that lots of people will look at, etc.), you might be able to
increase page load performance and decrease server load significantly by
creating a servlet that implements the getLastModified() method. That made a
huge difference in page load times on a project I worked on.
-Max
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Image References From JSP Pages inside WEB-INF
Posted by Micael <ca...@harbornet.com>.
Okay! I'm with you. How do you do that? What about
includes? Frames? Can you give me a bit of an overview of what the
mechanism here are? Sort of like learning how to fish rather than getting
a fish? Thanks, Jim.
Micael
At 04:17 PM 1/24/03 -0500, you wrote:
>3 words..........don't do that.
>
>If you must secure images, css, etc, then a filter is your best bet.
>
>
>
>--
>James Mitchell
>Software Engineer/Struts Evangelist
>http://www.open-tools.org/
>
>"The man who does not read good books has no advantage over the man who
>cannot read them."
> - Mark Twain (1835-1910)
>
>
>
>
>
>
>
> > -----Original Message-----
> > From: Micael [mailto:caraunltd@harbornet.com]
> > Sent: Friday, January 24, 2003 4:15 PM
> > To: struts-user@jakarta.apache.org
> > Subject: Image References From JSP Pages inside WEB-INF
> >
> >
> > How do you reference images, or other resources, from JSP
> > pages inside
> > WEB-INF if you want the images inside WEB-INF too?
> >
> >
> > LEGAL NOTICE
> >
> > This electronic mail transmission and any accompanying
> > documents contain
> > information belonging to the sender which may be confidential
> > and legally
> > privileged. This information is intended only for the use of the
> > individual or entity to whom this electronic mail
> > transmission was sent as
> > indicated above. If you are not the intended recipient, any
> > disclosure,
> > copying, distribution, or action taken in reliance on the
> > contents of the
> > information contained in this transmission is strictly
> > prohibited. If you
> > have received this transmission in error, please delete the
> > message. Thank you
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:struts-user-> unsubscribe@jakarta.apache.org>
> > For
> > additional commands,
> > e-mail: <ma...@jakarta.apache.org>
> >
> >
>
>
>--
>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
LEGAL NOTICE
This electronic mail transmission and any accompanying documents contain
information belonging to the sender which may be confidential and legally
privileged. This information is intended only for the use of the
individual or entity to whom this electronic mail transmission was sent as
indicated above. If you are not the intended recipient, any disclosure,
copying, distribution, or action taken in reliance on the contents of the
information contained in this transmission is strictly prohibited. If you
have received this transmission in error, please delete the message. Thank
you
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Image References From JSP Pages inside WEB-INF
Posted by James Mitchell <jm...@apache.org>.
3 words..........don't do that.
If you must secure images, css, etc, then a filter is your best bet.
--
James Mitchell
Software Engineer/Struts Evangelist
http://www.open-tools.org/
"The man who does not read good books has no advantage over the man who
cannot read them."
- Mark Twain (1835-1910)
> -----Original Message-----
> From: Micael [mailto:caraunltd@harbornet.com]
> Sent: Friday, January 24, 2003 4:15 PM
> To: struts-user@jakarta.apache.org
> Subject: Image References From JSP Pages inside WEB-INF
>
>
> How do you reference images, or other resources, from JSP
> pages inside
> WEB-INF if you want the images inside WEB-INF too?
>
>
> LEGAL NOTICE
>
> This electronic mail transmission and any accompanying
> documents contain
> information belonging to the sender which may be confidential
> and legally
> privileged. This information is intended only for the use of the
> individual or entity to whom this electronic mail
> transmission was sent as
> indicated above. If you are not the intended recipient, any
> disclosure,
> copying, distribution, or action taken in reliance on the
> contents of the
> information contained in this transmission is strictly
> prohibited. If you
> have received this transmission in error, please delete the
> message. Thank you
>
>
>
> --
> To unsubscribe, e-mail:
> <mailto:struts-user-> unsubscribe@jakarta.apache.org>
> For
> additional commands,
> e-mail: <ma...@jakarta.apache.org>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>