Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
    Bookmark Topic Watch Topic
  • New Topic

JSP converting my encoded quotes  RSS feed

 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi all,

How can I prevent JSP from converting an html encoded single-quote (#39) into an actual quote?
To be more specific, when I add it to a page using:

employee.name contains "John's" with an html encoded quote char, which is what I expected, but it actually renders as "John's" with an actual quote char.

Thanks for any assistance,
Rory

[ July 24, 2008: Message edited by: Rory Slegtenhorst ]

[ July 24, 2008: Message edited by: Rory Slegtenhorst ]
[ July 24, 2008: Message edited by: Rory Slegtenhorst ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
In order to determine that it is JSP (or specifically EL) that is converting this, you would need to view the HTML source; not what's showing in the browser window. You can do this from the 'view' menu of any browser.

Have you done this yet?
 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Ben Souther:
you would need to view the HTML source

Have you done this yet?


Yes, in both IE and Firefox with Firebug. The actual content sent back to the browser already contains the actual quote.
While debugging in Eclipse, I can see the correct value in the servlet just before I send it all to the JSP.

I have even created a small Delphi+Indy app to simply get the response and print it out. Here I am even more certain that there is no further translation of any encoded characters. And obviously it contains the quote as is (eg not the encoded version)...

PS.. it's hard to show what is actually in the string, as this board ALSO translates my encoded quote into a real one. In this case it is actually ONLY onscreen. The source of my post still contains the encoded version.

Thanks again in advance for any assistance,
Rory
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Using <cut> will encode the characters.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Rory Slegtenhorst:
it's hard to show what is actually in the string, as this board ALSO translates ...
Learn a bit about HTML entities in order to be able to control HTML displays.

For example was this:

&#39;

what you were trying to show?
 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear,

Yeah that is what I was trying to display

But why try to convert something back that was put in the right way?
So when my database actually contains &#39;, why isn't that being transmitted?

I will look into the cut though... see if that helps or not...

Thank in advance,
Rory
 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear,

And cut does something pretty funny LOL
It is actually translating the '&' and keeping the rest hahaha...

Now it prints:
&amp;#39;

Thanks again,
Rory
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Then you're not being clear. What is the text that's being passed to the JSP, what's in the HTML, and what do you want displayed?
[ July 24, 2008: Message edited by: Bear Bibeault ]
 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Originally posted by Bear Bibeault:
Then you're not being clear. What is the text that's being passed to the JSP, what's in the HTML, and what do you want displayed?


Servlet retrieving a POJO from Hibernate & returning to jsp:

empl.name contains "John&#39;s", retrieved from database. Eg a html encoded quote.

Part of test.jsp:

Here's the culprit... "${employee.name}"

Rendered HTML:

with the quote as a quote...

Expected HTML:

with the encoded version (which I am already passing)...

Please don't mind the '-' in on-click...
Hope this clears things up.
BTW... it IS hard to post anything on a forum that blocks most example code, regardless if I know my html entities LOL...
Rory
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Based on that you are claiming that the EL expression is converting the encoding. It doesn't as evidenced by this small test page that I wrote.


The renderred HTML:


Are you absolutely sure that employee.name is returning the undecoded value? I'm not convinced,
 
Rory Slegtenhorst
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
Bear,

After a long night of testing and trying I have found the reason on WHY it is happening. A solution to the problem however, I can't find.

And you are right. I have tried the same tests as you have, and even made a small test web to show the problem (together with the JMesa lib).
In all those cases I got the encoded version.

The real reason:
AJAX
Please consider the following AJAX call:

I have saved both "result" and "document.getElementById(div).innerHTML" to a file on disk, and found my problem.
The "result" actually contains my encoded version.
As soon as the result is assigned to the InnerHTML it's all gone.
Firebug shows this in proper detail (once you set js debugging LOL)

However, it still doesn't solve my problem. I just need to look for a solution in a different place

Thanks again and cheers,
Rory
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Closed. Continues in new topic in HTMl forum.
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!