Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
Forums Register Login
JSP page not displaying "
I have a JSP page where I write the text of an existing HTML page from an ArrayList where I have stored the lines of the HTML page. The reason I am breaking the HTML page into lines is that I want to highlight some words. My code contains:
DisplayForm displayForm = (DisplayForm)session.getAttribute("displayForm");
ArrayList<String> htmlStrings = displayForm.getHtmlStrings();
for (int i = 0; i < htmlStrings.size(); i++) {
String nextString = htmlStrings.get(i);
<% } %>
<%= nextString %>
<% }
} %>
The problem is that the page displays '?' where the HTML contains & (") and does the same thing for '. I suspect that other special characters are treated the same way. Please tell me how to solve this problem.


Alejandro Barrero
Please be sure to check the JSP FAQ to see if your problem has already been solved before posting. Thanks.
I don't see my problem is in the JSP FAQ. The link provided, has already been solved, doesn't answer the question because the problem is not with character in the file. The file displays perfectly in the browser, but the text created by the JSP changes characters from the string being written with <%= %>; it changes & to a ? and changes other characters like ' and " to ?.

The file displays perfectly in the browser

What file?
Have you used your browser's 'view source' feature to see if the characters in question are being altered by JSP or if they are just being interpreted by the browser?
Thank you for your prompt replies. First the file I am talking about is o.htm; a file that displays correctly in the browser (firefox or Internet explorer). Second, when I construct the the HTML text with the JSP all the text is the same as the original file except some characters like ", ' and -.
In the case of ". For some reason the original file some times contains the HTML equivalent which has & followed by # and 38 (it doesn't display in these posts) and some times it has a " that displays correctly (the original file was created with Microsot Word). Even the HTML equivalent of " is displayed as
I just created the JSP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<% String s = "\"&Test'"; %>
<%= s %>
The string appears correctly in the body and it displays "&Test'. So it appears that creating the HTML with Word for windows is giving problems; it has lots of css. After the test with the previous page, I know the problem is not JSP. It looks like I will never find out what's the problem.
Classic JSP expressions ( <%= s %> ) don't attempt to massage the output text.
Are you sure that one of the classes on your side isn't doing this?

Try printing the text (as it's coming out from your classes) to stdout and see if it's being escaped there.
Thanks for your replay Ben. My JSP is simply using <%= %>; the example in my previous post it works fine. I found out that the HTML file created with Word uses the value 8216 for '. The code:
<% String s = "'test'" + (char)8216 + "&"; %>
<%= s %>
Now I know what is the problem with the ' in the file. I can handle it and " and others.
I am puzzled that <%= s %> is mangling &.

Originally posted by Alejandro Barrero:
I am puzzled that <%= s %> is mangling &.

Again, it isn't.
Classic JSP expressions don't massage or escape text.
Something else is doing this.
Well, there is something strange going on. In my test JSP I only have:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<% String s = "'test'" + (char)8216 + "&"; String z = "Z";%>
<%= s %>
<%= z %>
And it is displaying:
'test'?& Z
Not only it's mangling the HTML representation of " but it is adding a blank after the string. I am running this with MyEclipse in Apache. I haven't tried in other systems.
It is a deep mystery. No other code created by me is intervening. It is so weird that we may never know.
At any rate thank you very much for your replies.
This sounds more like a character encoding issue.
Try printing that character as a string literal.
Catch Ernie! Catch the egg! And catch this tiny ad too:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database

This thread has been viewed 2991 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 25, 2019 00:22:34.