• 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

Returning spaces in the HTML

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a servlet which takes in a string entered by the user and displays it in HTML. This is all working unless the string has a space in it, in which cases the string is cut at the space. I know the escape character for the " is "quot;" and was wondering if there was a similar on for spaces?
Or is it the way I am including the variable in the HTML?

Thanks
Amy
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. The escape character for a space is &_nbsp;
[Remove the underscore between & and nbsp]
[ September 16, 2003: Message edited by: Mani Ram ]
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the space is displayed using &_#32 or &_nbsp. the first is prefereable.
in my servlet i built the message into one string before displaying it.
welcome = "Welcome " + value;
"</h2>
out.println("<html>" +
"<head><title>Welcome</title></head>" +
"<body background='../clouds.jpg'><h2>" + welcome +

dont know if any of that will help. not even sure the html is displayed properly in my servlet even because ive never logged on using a name with a space in it.
[ September 16, 2003: Message edited by: Randall Twede ]
 
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
I believe what Mani was trying to say is that the entity for a non-breaking space is &nbsp;. (Please proof-read your responses after posting).
However, I don't think that that might be the correct solution to your problem. You didn't really show where the problem is manifesting itself in your page. You might just need to quote your attributes (which you should always do in any case).
For example instead of generating:

be sure to generate:


Or better yet, after processing in the servlet forward to a JSP page for your display where such things are easier to keep straight.
hth,
bear
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic