This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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 '<' and '>' to the literal of '>'? Your prompt reply is greatly appreciated. [ September 24, 2003: Message edited by: verduka fox ] [ September 24, 2003: Message edited by: verduka fox ]
It most certainly has to do with the < character. As you have surmised you need to use the < 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 ]
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?
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
Joined: Jan 18, 2001
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.
[ September 24, 2003: Message edited by: Shabbir Rahman ]
-----------------<br />IBM XML Developer <br />SCJP 1.4
Joined: Jan 18, 2001
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 "<"). 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.
Joined: Feb 18, 2002
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 ]