Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP Session removes new lines from textarea

Status
Not open for further replies.
Jun 19, 2001
86
US
I am placing the contents of a textarea into a JSP session attribute. When I print the value of the Attribute the new lines are gone. It's like JSP is removing the formatting. Any ideas or tips would be appreciated.

Nathan
 
Before saving the text of textarea into JSP session attribute, replace the newline character by a sign you will not use in textarea.
Before display the text on textarea, replace the sign by newline
here is the code in jsp, it is a better habbit that you put it in javabean

<%@ page import=&quot;java.util.regex.*&quot;%>

<%
Pattern p = Pattern.compile(&quot;\n&quot;);
Matcher m = p.matcher(&quot;hello\nhello\nhello\nhello&quot;);
boolean result = m.find();
StringBuffer sb = new StringBuffer();
while(result) {
m.appendReplacement(sb, &quot;@&quot;);
result = m.find();
}
m.appendTail(sb);
out.println(sb.toString());

%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top