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 HTML, CSS and JavaScript and the fly likes & escape problem in HTML controls 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 » Engineering » HTML, CSS and JavaScript
Bookmark "& escape problem in HTML controls " Watch "& escape problem in HTML controls " New topic
Author

& escape problem in HTML controls

Terence Quigley
Greenhorn

Joined: Jul 14, 2008
Posts: 1
Hi,

I've noticed a discrepancy in how the & character is escaped in the <option and <input control statements in a Java 1.4.2 JSP page. Trying to display the string AT&T as the value in an <option HTML control statement displays AT&T as I expect but the same string in an <input HTML control statement returns AT. If the string is A & P Co then the <option HTML control statement displays A & P Co, again as expected. However the <input HTML control statement displays the string as A & P Co.

<select onchange='changeShownRecord(this);' name='vendor_name' size='1'>
<option value='604'>AT&T</option></select>
vs
<input type='text' name='vendor_name' size='35' maxlength='50' value=''/>

where vendor_name is the bean element containing the string (in this case AT&T).

I seems like there is some type of character encoding being performed but I don't if there is any way to control it. Can escaping be controlled or am I doing something wrong using the HTML control statements? Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

To be honest, I can't really tell what your issue is from what you've posted. But the & is the introductory character for HTML entities and you must be cautious when using it. To display an ampersand use the HTML entity &amp;


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: & escape problem in HTML controls
 
Similar Threads
JSP Help Regarding the Radio Button
Problem getting the Beer Selection Page screen shot
Passing a date
Returning a result set in an html form
Help wanted on control select/option by javascript