This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes escaping strings using Struts html:text tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "escaping strings using Struts html:text tag" Watch "escaping strings using Struts html:text tag" New topic
Author

escaping strings using Struts html:text tag

Colin Shine
Greenhorn

Joined: Aug 12, 2005
Posts: 26
Hi all,

I recently posted a question regarding how to escape quote characters generated by el expressions
(see the following link: http://www.coderanch.com/t/288914/JSP/java/el-expressions-escaping-Javascript-strings)

Bear Bibeault answered superbly may I add

Now I'm stuck with a similar problem with a Struts custom tag, specifically the html:text tag. It's trying to display a String containing a single quote (') and is escaping the quote with the sequence


The previous solution was to write an el function that parsed the String and prededed any occurances of ' with a \.

Does anyone know how I can do something similar with a Struts custom tag?
Colin Shine
Greenhorn

Joined: Aug 12, 2005
Posts: 26
Sorry, that didn't display as I had hoped... View the page source if you want to see the escape characters.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Can you show the html:text tag you are using?
How are you setting its value?
Colin Shine
Greenhorn

Joined: Aug 12, 2005
Posts: 26
Sorry about the time delay, I guess I'm across the pond from you guys. I've been looking deeper into the problem, and it doesn't seem to be anything to do with the Struts tag, rather it seems to be a browser issue. I'm totally stumped...

I ripped out the Struts html:text tag and replaced it with a regular, old-fashioned text input field. I hard-coded a last name in the "value" attribute as follows:



For some reason, it's still appearing as O& #39;Reilly (I've put a space in so the escape characters are displayed this time)

I have tried to replicate this on my desktop with a static html page but it won't work.
Colin Shine
Greenhorn

Joined: Aug 12, 2005
Posts: 26
Solved it!

A bean:write tag was being used further down the page to generate some javascript to update the value of the text box. Evidently, bean:write encodes characters such a quotes, which is fine in the body of a html page, but is displayed exactly 'as is' in the text field.



This javascript overrides the initial value, even my hard-coded one :roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: escaping strings using Struts html:text tag
 
Similar Threads
howto pass parameter to struts tag ?
Static varaibles
custom tag
Reading from database and putting into Combo Box
struts-jstl-struts