File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to display text with \n,\r in jsp from textarea? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to display text with \n,\r in jsp from textarea? " Watch "how to display text with \n,\r in jsp from textarea? " New topic
Author

how to display text with \n,\r in jsp from textarea?

tejz teja
Greenhorn

Joined: Feb 12, 2010
Posts: 7
I am wondering as how all these sites (like this Expert-Exchange, hotmail, etc etc) works which are able to show all

kind of chars (KEEPING format) in your mail/postings. All these data are entered in the TextField (like this one,

where a I am typing this content), which goes to some database (like Oracle in mycase). And then they are able to

show the whole data back in some TextArea without any problem. I think if I start taking care of each special char

for me (like new line, ', " etc) then there could be no end for my code. I believe there should be some mechanism by

which whatever data you get from DB (Oracle) --> JSP Java String object --> HTML TextArea and Vice-Versa without

loosing any data and preventing the "Unterminated string constant". I believe that some sort of encoding and

decoding need to be done, but what those are? How all these sites do it.

Textarae:------

<tr>
<td><span>NOTES :-</span></td>
<td>   <TEXTAREA Name="notes" rows="4" cols="30"></TEXTAREA></td>
</tr>

JavaScript:----

var notes=document.Form.notes.value;
notes = notes.replace(/\n\r?/g, '
');

and saving it in db...as string..
and again retrivewing from db:------
notes = resultset.getString("notes");
notes = notes.replace("
","\n"); <--- is it corerect?

and displaying in jsp:----
<%
String notes =request.getAttribute("notes").toString();
out.println(notes);
%>


upto here ok....when i am edittng that notes in jsp as below:--
<tr>
<td><span>NOTES</span></td>
<td>:  <html:textarea rows="6"

cols="30"name="searchPrfForm" property="fprofilevo.notes" styleId="notes"/></td>
</tr>

here also showing correct ,..but when i was click submit button..it was showing error as unterminated string constant error..

on svae function:---
var notes=document.getElementById("notes").value;
notes = notes.replace(/\n\r?/g, '
');

tell me ..where i have to modify it?
how to display text with \n,\r in jsp from textarea?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.

Test areas will already keep the original formatting. Where formatting is "lost" it's simply because of how HTML works: extra whitespace is ignored. If you want the original formatting to be maintained when the HTML is rendered you need to convert spaces to HTML   entities, CRLFs to <br/> tags, and so on.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Please take the time to choose the correct forum for your posts. This forum is for questions on JSP. For more information, please read this.

This post has been moved to a more appropriate forum.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to display text with \n,\r in jsp from textarea?
 
Similar Threads
servlet mapping
Resetting Values in JSP Page
Can not Populate the form on combo box change
Getting null while trying to get value of Multiple list
Getting "not a multipart request" even though the image is being saved.