• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing ANSI character 34 in request.setAttribute(String)  RSS feed

 
Keith Harrison
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

Sting Example: Drum Diameter 50" (1270mm)

I have a servlet that looks up values from a database and passes them through to a JSP as request attributes. As the values from the database are imperial measurements and include the " character, I find that when I assign input boxes with the string value, the string is trimmed to the position where the " appears. For some reason with MySql some values are stored as � and some are stored as ". The latter cause problems!

Is there a way, without checking the string value and replacing the ANSI character 34 (") that the strings values can be processed the way I want them to? Could the content/charset part of the page have anything to do with this?

I would be grateful for any advice you can offer.

With thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the generated HTML. You will find that the quote character is boofing up the HTML itself. It has nothing to do with JSP or request attributes.

Just like any other HTML page, you'll need to use a character entity in place of quote characters to make sure your HTML is valid.
 
Keith Harrison
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the guidance.

I have toyed with the idea and come out with the following class:



Then in my jsp I use:


This way I should be able to re-use the class and add other replacements as I find them.

Thanks again.
[ August 17, 2006: Message edited by: Keith Harrison ]
 
Rusty Smythe
Ranch Hand
Posts: 93
Mac Objective C Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might consider using Jakarta Commons (commons lang).

Here's how you'd use it in your example:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm, all you need to do is to use the <cut> JSTL tag which handles encoding things properly for you.
 
Keith Harrison
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rusty Smythe:
You might consider using Jakarta Commons (commons lang).

Here's how you'd use it in your example:



Although I welcome all suggestions thats more like what I was looking for. Thanks very much.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!