This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes How to insert a SPACE in a JSP expression? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "How to insert a SPACE in a JSP expression?" Watch "How to insert a SPACE in a JSP expression?" New topic
Author

How to insert a SPACE in a JSP expression?

Jen Yang
Greenhorn

Joined: Jul 07, 2003
Posts: 11
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.
Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
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 ]

SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam
Jen Yang
Greenhorn

Joined: Jul 07, 2003
Posts: 11
Thanks Vijay, works!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to insert a SPACE in a JSP expression?
 
Similar Threads
mysql & incomplete insertions!
print string with breaks on web page
Question ID :1000043338670
get data from Document object
Anything wrong this regular expression