JSP output string with HTML query  
Author Message
jungewum





PostPosted: 2004-9-15 10:08:00 Top

java-programmer, JSP output string with HTML query Hi,
I would like to output a string in a JSP page. The string contains
HTML tag.
How do I display the HTML version of the string in JSP?

e.g. String str = "<b><u>bold and underlined</u></b>";

In JSP, I use <%=str%>

Instead of displaying the HTML version of the string (with bold and
underlining of the text), the above string is displayed. Can you help?

Thanks,
June.
 
Andrew Thompson





PostPosted: 2004-9-15 11:05:00 Top

java-programmer >> JSP output string with HTML query On 14 Sep 2004 19:08:03 -0700, June Moore wrote:

> I would like to output a string in a JSP page.
..
> e.g. String str = "<b><u>bold and underlined</u></b>";

<% out.print(s); %>

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Andrew Thompson





PostPosted: 2004-9-15 11:07:00 Top

java-programmer >> JSP output string with HTML query On Wed, 15 Sep 2004 03:04:39 GMT, Andrew Thompson wrote:

> On 14 Sep 2004 19:08:03 -0700, June Moore wrote:
>
>> I would like to output a string in a JSP page.
> ..
>> e.g. String str = "<b><u>bold and underlined</u></b>";

// correction
<% out.print(str); %>
 
 
Tony Morris





PostPosted: 2004-9-15 13:27:00 Top

java-programmer >> JSP output string with HTML query
"June Moore" <email***@***.com> wrote in message
news:email***@***.com...
> Hi,
> I would like to output a string in a JSP page. The string contains
> HTML tag.
> How do I display the HTML version of the string in JSP?
>
> e.g. String str = "<b><u>bold and underlined</u></b>";
>
> In JSP, I use <%=str%>
>
> Instead of displaying the HTML version of the string (with bold and
> underlining of the text), the above string is displayed. Can you help?
>
> Thanks,
> June.

Your JSP is correct.
I'm guessing you aren't running the code on a servlet container, but a web
server.
Why you would write code like that I don't know, but then, I've seen some
strange stuff in JSP before.

--
Tony Morris
http://xdweb.net/~dibblego/


 
 
Andrew Thompson





PostPosted: 2004-9-15 14:09:00 Top

java-programmer >> JSP output string with HTML query On Wed, 15 Sep 2004 05:26:49 GMT, Tony Morris wrote:

> "June Moore" <email***@***.com> wrote in message...
..
>> e.g. String str = "<b><u>bold and underlined</u></b>";
>>
>> In JSP, I use <%=str%>
>>
>> Instead of displaying the HTML version of the string (with bold and
>> underlining of the text), the above string is displayed. Can you help?

I thought at first that 'the above string'
meant you saw this (literally) in the final page..
'<b><u>bold and underlined</u></b>'...

> Your JSP is correct.
> I'm guessing you aren't running the code on a servlet container, but a web
> server.

..but Tony's comment made the penny drop.

If the 'bold/underlined' string appeared in an
HTML page it would render as HTML, whereas the
second JSP command '<%=str%>' would vanish completely.

But if your server is neither configured to run
.jsp's, and does not send the content to the
client as an HTML content type, you would see all
the code of the original JSP as written by you.

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology