JSP store and read carriage return line break __js

Source: Internet
Author: User

In the JSP page, return line feeds are stored in the table method
1. Enter a section of text in a textarea, with line breaks, insert newline characters into the database
Use the following methods:
public static string texttohtml (String sourcestr)
{
int strlen;
String restring= "", Destr = "";
strlen = Sourcestr.length ();
for (int i=0;           i<strlen; i++)
{
Char Ch=sourcestr.charat (i);
Switch (CH)
{
Case ' < ':
Destr = "&lt;";
Break
Case ' > ':
Destr = "&gt;";
Break
Case '/':
Destr = "&quot;";
Break
Case ' & ':
Destr = "&amp;";
Break
Case 13:
Destr = "<br>";
Break
Case 32:
Destr = "&nbsp;";
Break
Default:
Destr = "" + ch;
Break
}
restring = restring + destr;
}
Return "" + restring;
}
2. Read from the database to retrieve the car line feed
If the JSP page read <br> can not wrap (at this time JSP read may be "<" escaped to &lt; ">" escaped into &gt; Cannot wrap at this time, you can do so in the Java method
The saved string contains <br> characters to be replaced with other words Furu: ReplaceAll ("<br>", "# (or other)");
In the JSP page with JS to replace the characters above replaced again into &LT;BR&GT, the replacement value assigned to the JSP need to display the place can;
JS replacement such as: Var str=str.replace (//#/g, "<br>")
document.getElementById ("id"). value=str;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.