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!

Martina
  • 1,760
  • 7
  • 39
  • 74

3 Answers3

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

Community
  • 1
  • 1
MaVRoSCy
  • 17,401
  • 14
  • 78
  • 121
2

this CSS worked for me,

white-space: pre-line;

sean717
  • 10,491
  • 19
  • 62
  • 82
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?

Community
  • 1
  • 1
Grofit
  • 16,417
  • 21
  • 91
  • 170