• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1878
  • Last Modified:

Html table ignoring newline characters in a string

Hi, I'm trying to display SQL, which is stored as a string, in a table.

When I debug i can see that the newline characters are in the string, but when it displays its just a big clump.

this is what i have on my jsp page:

<table>                  
     <tr class="tableHeader"><th>Name</th><th><bean:write name="Query" property="name"/></th></tr>
     <tr>
              <td class="TableRowH" align="right">SQL Statement:</td>
              <td class="TableRowH" ><bean:write name="Query" property="sql" filter="false"/></td>
     </tr>
</table>

and the string looks like: select  \n\t \t  columns from table where condition...

so how do it get the table to recognize the newline characters?
0
joycie237
Asked:
joycie237
1 Solution
 
BobTheViolentCommented:
I think it may be the browser ignoring the newlines.  Most are programmed to ignore multiple or "unneeded" spaces or newlines.

You could try doing a find/replace function and swap any "\n" for a html "<BR>" maybe.
0
 
LordOfPortsCommented:
Try enclosing the output in <pre> tags http://www.w3schools.com/TAGS/tag_pre.asp e.g.:
<table>                  
 <tr class="tableHeader">
  <th>Name</th>
  <th><bean:write name="Query" property="name"/></th>
 </tr>
 <tr>
  <td class="TableRowH" align="right">SQL Statement:</td> 
  <td class="TableRowH"><pre><bean:write name="Query" property="sql" filter="false"/></pre></td>
 </tr>
</table>

Open in new window

0
 
aralvareCommented:
why do you have the 'filter="false"'. If filter is false, then the framework does not translate the \n\t and other to proper html syntax.

try:
<bean:write name="Query" property="sql" filter="true"/>

Open in new window

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
joycie237Author Commented:
Thank you! The <pre> tag worked. It made my text a lot smaller though, is there any way to get it bigger again? Sorry I'm new to all of this, so I have no idea...
0
 
LordOfPortsCommented:
Yes, you can format the text within the <pre> tags, simply add the CSS code below to the <head> section of the web page or to your CSS file. You can change the font type as well as the size:
<style type="text/css">
    
    pre
    {
        font-size: 16px;
        font-family: Courier New;
    }
    
</style>

Open in new window

0
 
joycie237Author Commented:
Thank you so much! you're a lifesaver!
0
 
joycie237Author Commented:
yay! that fixed the font thing too!
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now