R
Russ Perry Jr
We have some images that we want to output on a JSP, and the name of
the image corresponds with an ID that we've gotten from a database.
What we've been doing so far is this:
<img src="specialimages/<bean:write name="ImageBean"
property="fileName"/>"
alt="special image" />
But, now we've done two things: 1) we put a filter on to prevent
unauthorized access, and 2) disabled cookies. This combination means
that access to the above no longer works, even for authorized users.
Basically, the session info was in a cookie, but now with no cookies,
we need it in the URL, but it isn't there.
We can't just use <html:img> directly, as the <bean:write> is nested
within it and therefor it gives a NullPointerException at compilation
time. The solution? We did this:
<jsp:useBean id="ImageBean" scope="session"
class="monitoronline.ImageBean" />
<html:img page='<%= "/specialimages/" + ImageBean.getFileName() %>'
alt="special image" />
Now, this raises some questions...
1) Why is the <jsp:useBean> necessary here, when it wasn't before? We
assume the <bean:write> mechanism makes the <jsp:useBean> unnecessary,
but don't see a reason why.
2) I'd like to avoid embedded Java if at all possible, so is there
another way to do this with just tags? [Note: we're not using JSTL,
at least not at the moment]
3) Might the "nested" taglib help here? It didn't look like it to us,
but maybe we're just missing something...
It looks like we also have the same issue with an <a> tag elsewhere:
<a href="docs/<bean:write name="doc" property="docLocation"/>">
....so we'll be looking for a fix for that case too, I guess.
Anyone?
the image corresponds with an ID that we've gotten from a database.
What we've been doing so far is this:
<img src="specialimages/<bean:write name="ImageBean"
property="fileName"/>"
alt="special image" />
But, now we've done two things: 1) we put a filter on to prevent
unauthorized access, and 2) disabled cookies. This combination means
that access to the above no longer works, even for authorized users.
Basically, the session info was in a cookie, but now with no cookies,
we need it in the URL, but it isn't there.
We can't just use <html:img> directly, as the <bean:write> is nested
within it and therefor it gives a NullPointerException at compilation
time. The solution? We did this:
<jsp:useBean id="ImageBean" scope="session"
class="monitoronline.ImageBean" />
<html:img page='<%= "/specialimages/" + ImageBean.getFileName() %>'
alt="special image" />
Now, this raises some questions...
1) Why is the <jsp:useBean> necessary here, when it wasn't before? We
assume the <bean:write> mechanism makes the <jsp:useBean> unnecessary,
but don't see a reason why.
2) I'd like to avoid embedded Java if at all possible, so is there
another way to do this with just tags? [Note: we're not using JSTL,
at least not at the moment]
3) Might the "nested" taglib help here? It didn't look like it to us,
but maybe we're just missing something...
It looks like we also have the same issue with an <a> tag elsewhere:
<a href="docs/<bean:write name="doc" property="docLocation"/>">
....so we'll be looking for a fix for that case too, I guess.
Anyone?