Hello!
I should probably know this but I have some HTML in a variable (loaded
from a database), and want to output it to a JSP file (you know what I
mean). I'm using the following code:
<% String ImageHTML = "<a blah blah blah>Link</a>";
...
<%=ImageHTML%>
But when I load it up it literally prints the HTML and in the source
it looks like:
<a blah blah blah> ....
How do I output it so it acts like HTML rather than a string of text?
I googled but something like this is difficult to find since I don't
quite know specific keywords that aren't too general.
Ta...
Lew - 30 Aug 2007 14:30 GMT
> Hello!
> I should probably know this but I have some HTML in a variable (loaded
> from a database), and want to output it to a JSP file (you know what I
> mean). I'm using the following code:
> <% String ImageHTML = "<a blah blah blah>Link</a>";
The Sun-recommended and almost universally applied convention is for variable
names to begin with a lower-case letter.
> ....
> <%=ImageHTML%>
[quoted text clipped - 6 lines]
> I googled but something like this is difficult to find since I don't
> quite know specific keywords that aren't too general.
<a href="<%= imageHTML %>"><%= imageHTML %></a>
Best practices prohibit the use of scriptlet in JSP. Use tag libs like JSTL
instead:
<a href="${imageHTML}"><c:out value="${imageHTML}"/></a>

Signature
Lew
Daniel Pitts - 30 Aug 2007 16:29 GMT
On Aug 30, 2:49 am, "christrid...@googlemail.com"
<christrid...@googlemail.com> wrote:
> Hello!
> I should probably know this but I have some HTML in a variable (loaded
[quoted text clipped - 13 lines]
>
> Ta...
This is a guess, I haven't tried it...
<% getOut().println(imageHTML) %>
Manish Pandit - 30 Aug 2007 17:58 GMT
On Aug 30, 2:49 am, "christrid...@googlemail.com"
<christrid...@googlemail.com> wrote:
> Hello!
> I should probably know this but I have some HTML in a variable (loaded
[quoted text clipped - 13 lines]
>
> Ta...
You can use escapeXml=false in the c:out tag that Lew pointed out, to
ensure the HTML does not end up being escaped as < etc.
-cheers,
Manish
christriddle@googlemail.com - 31 Aug 2007 09:28 GMT