• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Expression question

 
Harish Chandra Durgapal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a simple JSP Expression question
<%=" MY NAME IS JOHN "; >

The above tag prints MY NAME IS JOHN.
It deletes the leading and trailing spaces and the spaces between two words as well.
In my case i used following tag
<%= fun();>

fun() is a function that returns dynamic data say for e.g " MY NAME IS JOHN ".
It prints MY NAME IS JOHN to me but I have many spaces between two words.
Cant I print the value of fun as it is with out removing the spaces between words.

Is the expression tag removes the extra spaces between two words.
I want to print the value as return by fun() on jsp.

Please guide.
Thanks
Harish.
[ October 11, 2007: Message edited by: Harish Chandra Durgapal ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Harish Chandra Durgapal:
<%=" MY NAME IS JOHN "; >

he above tag prints MY NAME IS JOHN.


No, it doesn't. it gives you a translation error as the trailing semi-colon is invalid.

Ignoring that...

The spaces are not being removed by the JSP engine. They are dutifully being written to the HTML response. HTML itself does not handle spaces literally. All contiguous whitespace is collapsed as if a single whitesapce character has been present.
[ October 11, 2007: Message edited by: Bear Bibeault ]
 
Harish Chandra Durgapal
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear Bibeault ,

trailing semicoln was a mistake.
As I am printing the data return by fun() with in
<TD> tag of html.This is html that removing the extra spaces between words to a single.
Regards,
Harish
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Harish Chandra Durgapal:
trailing semicoln was a mistake.

Such posting errors can make getting answers to your question difficult. Please read this for more information.

This is html that removing the extra spaces between words to a single.
Browsers, when renderring HTML will treat contiguous whitespace as a single whitespace character. You might be able to get the effect you want by using non-breaking space entities (&nbsp;).
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
May be you can also use <TD><PRE>"your JSP expression</PRE></TD>
This will also maintain the white spaces.
regards
Amit
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!