This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pre tag causes text not to appear?

 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have the following code displayed:

However, no text is displayed on the page. I'm sure it has to do with the first character inside the <pre> tag is '<'. Is this a known issue? Is there a utility to convert '<' to the literal of '&lt;' and '>' to the literal of '&gt;'? Your prompt reply is greatly appreciated.
[ September 24, 2003: Message edited by: verduka fox ]
[ September 24, 2003: Message edited by: verduka fox ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It most certainly has to do with the < character. As you have surmised you need to use the &lt; entity. If the value is the result of a JSP substitution, it's easy to write a utility that converts character like <, >, & and the like to their entity references. I know of no standard Java class that performs this function.
hth,
bear
[ September 24, 2003: Message edited by: Bear Bibeault ]
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear,
Thanks for your response. I thought that by using the pre tag that the contents of the tag were displayed exactly as written. For example, multiple spaces are not consolidated as a single space; they are all written as spaces. Therefore, I assumed that the other characters in the pre tag would be observed in the same manner. False assumption?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, while the pre tag will preserve new lines and spaces, and render the content in a fixed-width font, you must still use character entities for special HTML characters such as the angle brackets and the ampersand.
bear
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so now I'm trying to develop a method to parse through a String, detect any ampersand or angle brackets and change them to the special values. This seems to work but doesn't seem very efficient. Is there a better way to implement this? I look for the ampersand first, since putting it last would find the ampersands in the special values for the angle brackets.
 
Dorothy Finkel-Laverty
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Verduka - take a look at the String class' "replace" methods - you can probably handle this in one or two lines of code.
 
Shabbir Rahman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you searching for following type of code

[ September 24, 2003: Message edited by: Shabbir Rahman ]
 
verduka fox
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dorothy and Shabbir,
Thanks for your suggestions. Dorothy, I can't use the replace method because this method requires a char to be replaced with a char. I need a char to be replaced with a String (i.e. ;<' replaced with "&lt;"). Shabbir, I'm using WebSphere Application Server 4.0.3 which only supports 1.3. Unfortunately, the replaceAll method is in 1.4.
Do you have any other suggestions?
One more question: On the same page as the code that I originally questioned is this code:

This displays without a problem. Is there a reason that the first caused a problem? Is it because the character after the < is a letter instead of a number that it causes a problem?
Your suggestions are greatly appreciated.
 
Shabbir Rahman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is the replaceAll code of String class of 1.4

So you can easily use the following code in your class

Before doing that you need to import java.util.regex.Pattern. I don't know whether 1.3 has regular expression package or not.
[ September 24, 2003: Message edited by: Shabbir Rahman ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65228
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know whether 1.3 has regular expression package or not.

It does not. To use regular expressions under 1.3 you might want to check out the Jakarta regex project. I use it regularly.
hth,
bear
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic