1

I have this problem: I have an HTML textarea which is filled by the user. (And he can press The enter button to go on a new line). Then I take The value of The textarea using the command:

document.getElementById("textareaCommento")

And I pass The value to the servlet using an XmlHttpRequest. In The servlet I save this value in a database. Since this point I have no problems...

Then, in another part I want to get The values from The database. Using a servlet I make this query

Select * from comments

And I transform the results in json. Here I have The problem... The newline character makes my JSON string invalid. For example:

"Comment":"hello
Word"

How can I do? Thanks in advance!

4

3 に答える 3

2

You have to replace the \n character from database to something like <br/>

For the replace see replace \n and \r\n with <br /> in java

于 2012-10-24T07:39:32.827 に答える
2

this CSS worked for me,

white-space: pre-line;

于 2018-10-08T00:15:34.720 に答える
0

You should be able to url encode your values so hello world would actually become "hello%20world", to do it in java see here:

Encoding URL query parameters in Java

To do it in javascript see here:

Encode URL in JavaScript?

于 2012-10-24T07:37:16.370 に答える