aspose file tools*
The moose likes JSP and the fly likes JSP page not displaying Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP page not displaying "" Watch "JSP page not displaying "" New topic
Author

JSP page not displaying "

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 316
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


Your help will be greatly appreciated,
Alejandro Barrero
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61222
    
  66

Please be sure to check the JSP FAQ to see if your problem has already been solved before posting. Thanks.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 316
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

Joined: Jan 10, 2002
Posts: 61222
    
  66

The file displays perfectly in the browser
What file?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 316
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Aug 01, 2005
Posts: 316
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Aug 01, 2005
Posts: 316
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

Joined: Dec 11, 2004
Posts: 13410

This sounds more like a character encoding issue.
Try printing that character as a string literal.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP page not displaying "