• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

runtime encoding probolem

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi folks
In my jsp iam going to populate special characters (<>(*&), it is
working fine, but if i substring that one to certain limit(for ex:10)
for example if i give like --> &<> to populate in jsp it is
taking as --> &<> and it is going to substring and it is
taking upto--> &<&
but the xml parser not able to parse and thrown NotWellFormed exception
how can i overcome this one.
Advance appreciation for any ideas..

-Naresh
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is usually safer and less error-prone to send any data containing special characters to be encoded before flushing it to the client. You can find a list of special character mappings here. If you rely on sending data as-is, then you can never be quite sure as to how different browsers might interpret special characters as. Some will render it properly or some might engage in escaping the characters on their own.
 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anirvan
thank you for valuable information,as you said i tried before
rendering...
in my java file i decode special characters using URLDecoder like

but it is not decoding and same encoded data is populating..
can you please let me know how can i do..

-Naresh
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me try and understand what your requirement is:
1. You are sending the string value=> &*<> from your server to the client.
2. The client is rendering &*<> fine, but when you do a substring on it, you're not getting the correct value. What is the index parameter you pass for substringing and what do you get as a result?
3. Where is the XML parser being used? Is it at the server side or the client side [using JavaScript]?
If it is at the server side, then you need to escape characters like=> &, < and >. Otherwise your parser is bound to throw an error.

And why are you using URLDecoder to "decode" the string before sending it to the client? Firstly, I don't think that you really need to escape special characters when displaying simple HTML output through a JSP. And secondly, you should be "encoding" and not "decoding" when you send the content to the client! The browsers are capable enough to decode on their own.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand where an XML parser is involved in using a JSP page, but unless those characters are part of an URL, URLEncoder/URLDecoder have nothing to do with this.

The way to transport special characters in XML is either to replace them by their escaped entities (e.g. & --> &amp; and < --> &lt;) or to wrap them in CDATA sections.

In JSP pages you may wish to investigate the JSTL <c:out> tag and its escapeXml attribute.
 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Anirvan
-->iam using RICO ajax ,in the jsp iam getting the vales from java file and iam going to populate it, while it is done it is parsing characters and populating in jsp.
-->in the substring function i had given like
iam getting Exception like..

XML Parsing Error: not well-formed


--> XML parser is used in javascript file like rico.js RICO ajax
there they had used DOMParser
--> In my java file iam replacing special characters using string.replaceAll(), and rendering to JSP

previously i havent done replacing , but now iam replacing and rendering the actual value but the xml parser again parsing like <> and populating in JSP. if i dont used substring the out put is well, but if i used <substring> it is parsing upto certain characters and giving parse exception..
[ May 06, 2008: Message edited by: Naresh Talluri ]
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright, so you're using Rico.js [not that I've used it ever] and then, you're also using a certain taglib tag : <str:substring start="0" end="18"/>. Again you don't mention which taglib this is, 'coz I certainly can't recall ever coming across such a taglib tag, which allowed me to do so.

Just a word of advice Naresh, you should try and provide as much information as possible so that those who try and help you out are in a better position to do so. Letting out information in installments serves no purpose.

Anyways, getting back to your problem, even though I can't comment upon the functioning of that unknown tag, I can only make a guess that it tries to substring the current string value which you print through the <c:out/> tag. I have a feeling that your substring tag works somewhat like a XSLT's template, where it takes the current string value enclosed between two tags and operates upon it. And since the characters "<" or ">" appear in that value some where, it retrieves a value which doesn't conform to something it expects.

Try this: Before sending the response to the JSP, just do a replace all on "<", ">" and "&", and replace them with a " " [space] character. If the error is removed this way, then it's the problem I've cited above. In that case, try the CDATA approach Ulf has suggested in his post.
 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had tried using CDATA but here i can avoid that error but it is not populating in JSP, because the XMLParser recognises onlyparsed elements, if i give like CDATA we are mark it as (dont parse).
And iam using taglibs-string.jar,jstl1.2.jar,standard.jar.
If we give ("") empty string whenever <,>,& occur, it should work fine.
coz parser wont find any special characters,if it find any special characters then only it should trying to parse..
and i tried almost all possibilities which i know, and iam not able to solve then decided to post.
[ May 06, 2008: Message edited by: Naresh Talluri ]
 
Anirvan Majumdar
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So well,
it seems atleast we've got one part right that the special "str" tag does in fact function upon the string value enclosed by the XML tag it's operating on. However I'm not too sure whether you're using a standard taglib. If you can post the taglib directive at the top of your JSP corresponding the "str" tag, then may be it might help us understand how does it actually work.

Going through the previous posts, I couldn't make out whether you've tried replacing => "<" with "<", ">" with ">" and "&" with "&" using the replaceAll() method in your server. Let us know if that helped.
 
Naresh Talluri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anirvan Majumdar:
So well,
it seems atleast we've got one part right that the special "str" tag does in fact function upon the string value enclosed by the XML tag it's operating on. However I'm not too sure whether you're using a standard taglib. If you can post the taglib directive at the top of your JSP corresponding the "str" tag, then may be it might help us understand how does it actually work.

Going through the previous posts, I couldn't make out whether you've tried replacing => "<" with "<", ">" with ">" and "&" with "&" using the replaceAll() method in your server. Let us know if that helped.




Iam using standard taglib
here is my code...


and previously in my java fiel iam replacing like
fieldValue.replaceAll("<","<");
 
It runs on an internal combustion engine. This ad does not:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic