• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to handle Multiline String in JavaScript in JSP page?

 
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?
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic