• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to handle Multiline String in JavaScript in JSP page?

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there

this is my JavaScript code that is I am using inside my JSP page


and then it shows problem of MultiLine text in JavaScript then I changed my code like this


but Values are not replacing

My Values Source is from mySQL database

Where is error?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot break lines inside a string in JavaScript. Why can't all the string be on the same line?

And of course you can't use code to fix syntax errors in the same code!
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Why can't all the string be on the same line?


I am getting all those values from textarea fields and I have not written any code for replacing newline text convert it to a single line and store in the database

What should I do know before setting that data in model to send to JSP page do I need to convert multiline text of db in a single line

or

change all text into a single line before storing data of textarea in db?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the newlines are not significant, I would strip them before storing them in the DB. You always want the data in your DB to be as clean as possible.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what about if new lines are significant?
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there be any problem of using JSTL?

I am using JSTL to fetch data from model that is send by controller to JSP page
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the code that can help you what is exact problem is



I am using JSTL(JSP StandardTag Library)

I ma getting value from my db exactly in this format but as like in this case when you run this script in a single browser check console I am getting similar error in my case to

"unterminated string literal"

I hope now you got some more Information about my problems
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kishor Joshi wrote:But what about if new lines are significant?

Then replace them with new-line literals ('\n') so that they don't create syntax errors in your JavaScript.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!