0

I am developing a Web Application with JSP and Servlet that involve user writing and sending feedback in a textarea and saving it to the database. Suppose the user enter like this:

Error here
Need fixing there
Bug everywhere

I can use request.getParameter("textareaname") to get the content in the textarea and save it in the database. But the saved result and the data retrieve will be:

Error here  Need fixing there  Bug everywhere

Is there a way to keep the text area format as how the user enter it? As in keep the line break? Any help is appreciate

user3676506
  • 102
  • 10
  • Maybe this helps you http://stackoverflow.com/questions/10062358/storing-textarea-data-with-line-breaks-in-database-and-displaying-in-same-format – RubioRic Apr 07 '16 at 12:06
  • you just need to do encodeURIComponent($("#idOfTextArea")) in the request url in javascript and only get value by request.getParameter("textareaname") and save into DB –  Dec 23 '17 at 14:43

1 Answers1

0

The string obtained by request.getParameter("textareaname") contains the line breaks.

When you save it to the database and read it back and the line breaks are gone, then you need to review your database code why it has replaced or stripped of the line break characters.

wero
  • 32,544
  • 3
  • 59
  • 84
  • @BalusC what exactly is untrue – wero Apr 07 '16 at 12:15
  • 1
    @BalusC How do you know? The question does not talk about presenting a string. It is about that a string posted by a textarea and saved to the database has lost its line breaks. There is a chance that the OP only tested that by looking at the string via a JSP so you could have raised that as a comment. Instead you just guessed that, closed the question and downvoted my answer. I really think you are shooting too fast. – wero Apr 07 '16 at 12:24
  • @BalusC I did not say that a JDBC driver does that. I said that if during saving and reading from/to the database the linebreaks are gone the OP should check his database code. – wero Apr 07 '16 at 12:44
  • @BalusC we will not see because you closed the question. I just wished you would reflect a little bit about your own behaviour. Anyway I am out of this discussion. – wero Apr 07 '16 at 12:54