• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to display plain text in jsp without using pre, xmp, or code

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Java Ranchers,
Is there any method in jsp to encode the HTML so that I can display HTML tags say <b> <input type=text> ...etc
I don't want to use
<pre></pre> or
<xmp></xmp> or
<code></code>
as all these methods have limitations like horizontal scrolling etc.
There is a method URLEncode but that also does not serve my puropse
regards
George Joseph
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like you're creating a "tutorial" style page,
teaching people to use HTML. Of course, you need some
way to display valid HTML source in such pages.
You could use the entity codes for the ampersand, greater
than, less than, etc.
Show the <b> tag as <b>
The others work the same way.
< <
> >
& &
Hope that helps.
Joe
 
George Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Joe,
Do you mean that I have to replace all
"<" with "&lt;";
">" with "&gt;";
"\n" with "<BR>";
Is there no other automated method in JSP to ENCODE Html so that I can display plain text from my database as it is.

George

Originally posted by Joe Gilvary:
It sounds like you're creating a "tutorial" style page,
teaching people to use HTML. Of course, you need some
way to display valid HTML source in such pages.
You could use the entity codes for the ampersand, greater
than, less than, etc.
Show the <b> tag as <b>
The others work the same way.
< <
> >
& &
Hope that helps.
Joe


[This message has been edited by George Joseph (edited November 07, 2001).]
[This message has been edited by George Joseph (edited November 07, 2001).]
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may set content type in the jsp
<%@ page contentType="text/plain"%>
or create a method to translate all the html characters.
<%! public String translateHtmlChars( String string ){
}
%>
What is the problem you have with xmp ?
Happy coding

Originally posted by George Joseph:
Hi Java Ranchers,
Is there any method in jsp to encode the HTML so that I can display HTML tags say <b> <input type=text> ...etc
I don't want to use
<pre></pre> or
<xmp></xmp> or
<code></code>
as all these methods have limitations like horizontal scrolling etc.
There is a method URLEncode but that also does not serve my puropse
regards
George Joseph


 
George Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Zkr Ryz,
The problem with <xmp> is that is cause horizontal scrolling that is
If I enter in a textarea without new line (Enter key)then when I display using <xmp></xmp> the webpage will scroll horizontally that is the text won't be wrapped.
I want the plain text to be shown as it is without scrolling.
Have you any idea how this discussion/Messgae board works.
Here plain text is shown as it is without unwanted horizontal scrolling.

George

Originally posted by Zkr Ryz:
You may set content type in the jsp
<%@ page contentType="text/plain"%>
or create a method to translate all the html characters.
<%! public String translateHtmlChars( String string ){
}
%>
What is the problem you have with xmp ?
Happy coding


 
Joe Gilvary
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I look at a page source, I see the codes I
entered in my earlier message are encoded as
entity codes. Each post is strung out in the
HTML source as a looong line of output.
My guess is that the text is captured and converted
to use the entity codes, and the result is stored.
That result is fetched out for display when one of
use browses a thread.
So, the input I used to show the entity codes failed
above, and my earlier message doesn't display them
properly. (I didn't encode the ampersand at the start
of the entity code as you did.) It looks like you'll
need to write that method that Zkr Ryz suggests. Encode
all the codes that need to pass through the same way
you did the codes in your reply to my message.
I did something like that once, with XML inside a SOAP
method call on its way to/from an Oracle database. I
found I needed to use the numeric entity codes, but I
can't remember right now which component had trouble with
which specific entity code. If you're encoding anyway,
and don't have a driving need to let people read the input
from an SQL prompt, you might be better off with the
numeric codes.
Sorry about the mess up in my first post.
Thanks,
Joe
 
George Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Joe,
In ASP (Active Server Pages) there is a method called Response.HTMLEncode(html String), which will encode all < to &lt; and so on.
According to Mr. Zkr Ryz , I will have to write my own method say
<%! public String translateHtmlChars( String string ){
}
%>
But If anybody has written such a method in JSP let me know so that I can reuse the code as it will be a great help.

George

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to Java and had a similar problem. I wrote a little class I use to convert certain characters and it works fine for my app so I'll post it here and it may be useful to you as well.

Hope this helps,
Pat
 
George Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Pat,
Thanks for your code, I also appreciate your coding style and the selection of variable names.

George

Originally posted by Pat Wallwork:
[B]Hi,
I am new to Java and had a similar problem. I wrote a little class I use to convert certain characters and it works fine for my app so I'll post it here and it may be useful to you as well.

Hope this helps,
Pat[/B]


 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Guys!
I have a similar problem mentioned in this old post. I have created a method parseString(). Does anybody know if a similar thing can be achieved by jsp page directive attribute pageEncoding.

Thanks,
Martin
 
reply
    Bookmark Topic Watch Topic
  • New Topic