• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP page not displaying "

 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,

Alejandro Barrero
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to check the JSP FAQ to see if your problem has already been solved before posting. Thanks.
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64994
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The file displays perfectly in the browser
What file?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
<html>
<head>
</head>
<body>
<% String s = "\"&Test'"; %>
<%= s %>
</body>
</html>
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 %>
Prints
'test'?&
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 &.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alejandro Barrero
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there is something strange going on. In my test JSP I only have:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<% String s = "'test'" + (char)8216 + "&"; String z = "Z";%>
<%= s %>
<%= z %>
</body>
</html>
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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds more like a character encoding issue.
Try printing that character as a string literal.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic