• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Line Breaks and Special Characters with java Result

 
Greenhorn
Posts: 24
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

I am programming a website using Servlets and JSPs and I am currently having a problem that if I enter something into my database (MySQL 5.x) with a line break "\n" it will not show up when I run a query on that data through my servlet. For some context: I am entering the data into the database using my Servlet and JDBC/ODBC and using encodeURIcomponent when I pass it from my page to my servlet using jQuery/AJAX .post method, the line breaks show up in the DATABASE and that is just fine. The problem is, when I run a query on the information using my Servlet (get method from JSP) I get the ResultSet and then turn that ResultSet into a Result in my Servlet and then pass that Result to my JSP where I iterate over it, and the linebreaks are no longer showing up.

Here is my code where I get the ResultSet and Result and then pass it to the JSP:



If you need to see any more code please let me know.

Again my problem is, I am trying to enter data into the database with line breaks, those linebreaks are carried over by jQuery/AJAX to my servlet which uses JDBC/ODBC to enter the data into my MySQL 5.x database (where the line breaks DO SHOW UP) and then I run a query on that data using my servlet and the ResulSet is then turned into a Result which is passed to my JSP and iterated over and when it is outputted into the JSP, the linebreaks are NOT showing back up.

Any help would be greatly appreciated

Thanks,
Chris
 
Sheriff
Posts: 67665
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whitespace, including newlines, are irrelevant in HTML. If you want the newline to actually display as a a newline, you'll need to use HTML mechanisms to cause the text to wrap. <'br> is often used for this.
 
Chris Whited
Greenhorn
Posts: 24
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh okay. So it is in the html. In that case, should I use a Java replace method on the Result or ResultSet to replace the newline character with the <br> tag? Is that possible?
 
Bear Bibeault
Sheriff
Posts: 67665
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a <br> is what you need (it's not always) then that sounds like a simple string substitution prior to display.
 
Yeah. What he said. Totally. Wait. What? Sorry, I was looking at this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic