• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Returning spaces in the HTML

 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • 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
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • 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 ]
 
Randall Twede
Ranch Hand
Posts: 4439
3
Java
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic