Solution for JSP save to database lost format _jsp programming

Source: Internet
Author: User

What does the article on the website store? Using Oralce with CLOB storage, Java operation Clob method of a lot of online, but found that read after the display on the Web page and input when the format is completely different, the paragraph has ceased to exist.

Because the page uses a TEXTAREA tag instead of a powerful Web page text editor, so to deal with the format of their own problems, the following is a professional function I found, use it to pass the front of the article string escaped to save the database, this time again read the article will have a paragraph of the display.

Workaround code reference for JSP saved to database in lost format:

/**
 * Format the article information, keep the article format. used when saving.
 * 
 @param str
 * @return
 /Public
string HTMLEncode (String str) {
  str = str.replace (">", "& gt; ");
  str = str.replace ("<", "<");
  char ch;
  ch = (char) 32; Space
  str = str.replace (string.valueof (CH), "");
  ch = (char) 34; "
  str = str.replace (string.valueof (CH)," "");
  ch = (char) 39; '
  str = str.replace (string.valueof (CH), "'");
  ch = (char) 13; Carriage return
  str = str.replace (string.valueof (CH), "");
  ch = (char) 10; New line
  str = str.replace (string.valueof (CH), "<BR>");
  return str;
}

The above is and you share the JSP saved to the database lost format solution, I hope to learn some help, there are good ideas to welcome everyone to communicate and explore.

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.