js| Problem | In a Web application like a message board, you need to display large sections of text in <textarea> on a JSP page, so you need to treat special characters in text such as wrapping and space, as follows:
1, directly save, and then when removed from the database filter filtering method once again sent back to the page can be, to a piece of code, read the understanding, you can expand their
public static string filter (string value) {
if (value = = null)
return (NULL);
StringBuffer result = new StringBuffer ();
for (int i = 0; i < value.length (); i++) {
char ch = value.charat (i);
if (ch = = ' < ')
Result.append ("<");
else if (ch = = ' > ')
Result.append (">");
else if (ch = = ' & ')
Result.append ("&");
else if (ch = = ' ")
Result.append ("" ");
else if (ch = = ' \ r ')
Result.append ("<BR>");
else if (ch = = ' \ n ') {
if (i > 0 && value.charat (i-1) = = ' \ r ') {
2, in action with ReplaceAll () to replace the space return,
ReplaceAll ("\ r \ n", "<br>");
ReplaceAll ("", "\b");
In the JSP page, if you add Filter= "false" with <bean:write>,
<bean:write name= "info" property= "content" filter= "false"/>
3, using the style sheet, place a "transparent" <textarea> in the Display page, a text box that borders the color of the text box and the color of the textbox, and then place the displayed content in the text box so that no processing is required and exactly the same format as the user entered. Personally think it's the best way. Of course, remember to set this text box to read-only Ah, hey
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.