Solved

Html table ignoring newline characters in a string

Posted on 2008-10-30
7
1,852 Views
Last Modified: 2012-05-05
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
Comment
Question by:joycie237
7 Comments
 
LVL 2

Expert Comment

by:BobTheViolent
ID: 22843708
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
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 500 total points
ID: 22844207
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
 

Expert Comment

by:aralvare
ID: 22844500
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:joycie237
ID: 22845499
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
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22845866
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
 

Author Closing Comment

by:joycie237
ID: 31511785
Thank you so much! you're a lifesaver!
0
 

Author Comment

by:joycie237
ID: 22846557
yay! that fixed the font thing too!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now