• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to insert a SPACE in a JSP expression?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all
I have the following string:
String testString = "aaa bbb";
if I do an
out.println(testString);
It works fine. I get "aaa bbb".
But if I put it into a JSP expression like:
<input name="test" type="text" value=<%= testString %>>
then only the part before the <SPACE> ("aaa") will be shown in my text field.
How do I insert a <SPACE> into a JSP expression? Thanks.
 
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jen,

Change this statement :
<input name="test" type="text" value=<%= testString %>>
to:
<input name="test" type="text" value="<%= testString %>">
in your code.
You are missing " " in the value attribute as it contains a space.
[ July 29, 2003: Message edited by: Vijay Singh Rathore ]
 
Jen Yang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Vijay, works!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear in mind that this has nothing to do with the JSP expression, but with your lack of putting quotes around the attribute value. If you hard-coded the string with spaces into the HTML without the quotes you would observe the same behavior.
Lesson: always quote your HTML attributes as if you were writing xhtml.
hth,
bear
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic