• Post Reply Bookmark Topic Watch Topic
  • New Topic

Line Breaks and Special Characters with java Result

 
Chris Whited
Greenhorn
Posts: 24
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 Java Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!