Contact Us
  
 
 
    SearchSearch   RegisterRegister   Log inLog in 

Problem with view string in jsp

Problem with view string in jsp

 
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans
View previous topic :: View next topic  
Author Message
lungten



Joined: 08 Dec 2008
Posts: 2

PostPosted: Wed Dec 24, 2008 1:32 pm    Post subject: Problem with view string in jsp Reply with quote

Hello all

JSP is not printing String while fetching from database. I am using mysql database and JDBC for communication with database and JSP. All are fine, but sometimes, content from database not shown in JSP page.

Database field content

not working!!!!
Quote:

java is new jdk1.6
JSP is old
black



but working with
Quote:
java is new jdk1.6


This is content in mysql database
and If try to print, it not coming in JSP page.

But I do not face problem with single line content,
with only multiple line content in database is a problem
Back to top
View user's profile Send private message
seniormember
Site Admin


Joined: 20 Jul 2008
Posts: 77

PostPosted: Fri Dec 26, 2008 3:08 pm    Post subject: Reply with quote

This is problem of carriage return \r and new line \n in string. In database it is stored as new line \n and carriage return \r, and when fetching in JSP page, string cannot complete with opening " and ending " quots.

Simple solution for this, replace \n\r into html tag of <br>
Back to top
View user's profile Send private message
mehra2007



Joined: 13 May 2007
Posts: 4

PostPosted: Sat Dec 27, 2008 6:49 am    Post subject: Reply with quote

I have a trick to fight with new line and carriage return in JSP. I get this problem, so I removed all \n and \r with <br>

Code:
public String addHTML(String htmlString)
{
      String noHTMLString = htmlString.replaceAll("\\<.*?\\>", "");
      noHTMLString = noHTMLString.replaceAll("\r", " ");
      noHTMLString = noHTMLString.replaceAll("\n", "<br/> ");
        return noHTMLString;
}


Code:
<div><%=addHTML(rs.getString("text"))%></div>



It will not work with textarea tag of html. In textarea field of html, simply get \n and \r and view it. It convert automatically
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Java,Struts framework, Velocity, JSF, Hibernate, Servlet, JSP, javaBeans All times are GMT
Page 1 of 1

 
Jump to:  
  Quick Post a Reply Topic
     
  Name (required)  
     
  Email Address (will not be published) (required)  
     
  Subject of topic (required)  
     
   
     
   
     
  Advertisement  
     
 
     


  More Links  
 
JSP Introduction
JSP Setup
Simple JSP Example
JSP Variable
Array Declaration in JSP
JSP Forms and User Input
Form Validation
JSP Cookies
JSP Session Object
Loop, content collection, iterator, conditional check in JSP
JSP Application Object
JSP Include
JSP Response Object
JSP Request Object
JSP Error Handling
JSP File Handling Object
JSP Action Tag
JSP Implicit Objects
JSP Declaration
JSP Directive
JDBC Introduction
JDBC Driver
JDBC Connection
JDBC Prepared/Statement
JDBC ResultSet
JDBC Close Connection object
JDBC Insert
JDBC Display Records
JDBC Update
JDBC Delete
JDBC Sorting
JDBC Query
JDBC Exception
JDBC Add Batch
JDBC Transaction/RollBack