aspose file tools*
The moose likes Servlets and the fly likes Returning spaces in the HTML Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Returning spaces in the HTML" Watch "Returning spaces in the HTML" New topic
Author

Returning spaces in the HTML

Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
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

Joined: Mar 11, 2002
Posts: 1140
Yes. The escape character for a space is &_nbsp;
[Remove the underscore between & and nbsp]
[ September 16, 2003: Message edited by: Mani Ram ]

Mani
Quaerendo Invenietis
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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 ]

SCJP
Visit my download page
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61421
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Returning spaces in the HTML