Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Java Data Base Connection

data base connection

  • Please log in to reply
2 replies to this topic

#1 bixosaurus

bixosaurus

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:Java

Posted 07 May 2012 - 12:11 AM

Hello,

I need to let users interact with my web application so they can insert their personal comments.

I store these comments (with line breaks, tabs, spaces...) in a mysql DB, but when I get them from DB and display in JSP, no line breaks, tabs or spaces are shown...(I'm using Struts 2 < s : property value="comment"/>)

If I look how the comments are stored in DB (e.g with SqlDeveloper) I can see the line breaks, tabs and spaces

anybody knows how to solve this problem??
thanks in advance
  • 0

#2 papabear

papabear

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 472 posts
  • Location:DarkSide

Posted 07 May 2012 - 12:24 AM

How did you put the line breaks into your comment? did you put \n for every line break? if so here's a solution


public static String nl2br(String s) {
  return s.replaceAll("\n","<br/>");
}

the parameter is the comment :)
  • 0
Life has no CTRL+Z
Never Forget To HIT "LIKE" If I Helped

#3 bixosaurus

bixosaurus

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:Java

Posted 07 May 2012 - 12:42 AM

yes, as i have mentioned "If I look how the comments are stored in DB (e.g with SqlDeveloper) I can see the line breaks, tabs and spaces"


anyway thanks for your answer
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download