Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:23:00+00:00 2026-06-17T20:23:00+00:00

I appended \n to the String and when using s tag textarea, the newline

  • 0

I appended “\n” to the String and when using s tag textarea, the newline has been appended and data are shown line by line. But when I use c out tag, data are shown in one line. How can I show line by line using with c out tag?

StringBuffer sb = new StringBuffer();
    for (MyBean bean : beanList) {

                sb.append((bean.getName());
                sb.append("\n");
            }
            return sb.toString();

JSP

<c:out value="${myData}"/>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:23:02+00:00Added an answer on June 17, 2026 at 8:23 pm

    JSP produces HTML. In HTML, new lines are to be represented by the <br> element, not by the linefeed character. Even more, if you look in the average HTML source, you’ll see a lot of linefeed characters, but they are by default not interpreted by the webbrowser at all.

    Apart from using the HTML <br> element instead of the linefeed character,

    sb.append("<br />");
    

    and printing it without <c:out> like so ${myData}, you can also use the HTML <pre> element to preserve whitespace,

    <pre><c:out vaule="${myData}" /></pre>
    

    or just apply CSS white-space:pre on the parent element, exactly like the HTML <textarea> element is internally doing:

    <span style="white-space:pre"><c:out value="${myData}"/></span>
    

    (note: a class is more recommended than style, the above is just a kickoff example)

    The latter two approaches are recommended. HTML code does not belong in Java classes. It belongs in JSP files. Even more, you should probably actually be using JSTL <c:forEach> to iterate over the collection instead of that whole piece of Java code.

    <c:forEach items="${beanList}" var="bean">
        <c:out value="${bean.name}" /><br />
    </c:forEach>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using python I'm parsing several strings. Sometimes the string has appended several semicolons to
I wanted to append css stylesheet inside head tag but gets appended to body
Trying to do some 301 rewrites but an urls string is appended.. I think
I am using .append to fill in an empty list with a string but
Probably some simple derp but I just can't figure this out, I'm using almost
I have one specific problem while converting double values to string using sprintf() in
I have appended content (using ajax) to my document and my events are not
I have an array that contains string which may contain whitespaces appended to the
Can anybody guide me how to append query string to current url using jquery
I'm trying to convert an amount of seconds into a formatted string using midp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.