Reputation: 45
I have a JSP page with a text-area when user clicks save button, it saves the data from the text area to the database. DB field corresponding to data from text-area is Clob . I need to write this data to a file (after converting clob to String), by preserving newline. But when I convert Clob to String, the newlines are missing
Can I preserve newline while converting clob data to String.
Upvotes: 0
Views: 1187
Reputation: 13057
I assume, that you want to output your text on a JSP page. Therefore, you have to convert it to HTML.
Replace all new line characters with <br>
.
String html = text.replace("\n", "<br>\n");
Additionally, you should escape the special characters in your text to HTML entities. Use StringEscapeUtils#escapeHtml4()
from the Commons-Lang library.
Upvotes: 1