Html table ignoring newline characters in a string

Posted on 2008-10-30
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:

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

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?
Question by:joycie237
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

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.
LVL 19

Accepted Solution

LordOfPorts earned 500 total points
ID: 22844207
Try enclosing the output in <pre> tags e.g.:
 <tr class="tableHeader">
  <th><bean:write name="Query" property="name"/></th>
  <td class="TableRowH" align="right">SQL Statement:</td> 
  <td class="TableRowH"><pre><bean:write name="Query" property="sql" filter="false"/></pre></td>

Open in new window


Expert Comment

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.

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

Open in new window

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.


Author Comment

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...
LVL 19

Expert Comment

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">
        font-size: 16px;
        font-family: Courier New;

Open in new window


Author Closing Comment

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

Author Comment

ID: 22846557
yay! that fixed the font thing too!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eclipse with various Java releases 7 54
CSS in HTML 5 54
Where to place postgres JDBC driver jar on tomcat 8 33
form isn't working is it missing a document 21 32
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

696 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