Java Page Wrap Processing

Source: Internet
Author: User

The

text entered in the Taxtarea. If a carriage return or a space is included. It is not normal when it is displayed on the interface. The carriage return disappears and the space becomes shorter.
How to solve this problem. There are 2 ways.
1. Using <pre> tags
The pre element is defined by the "pre" element, which defines the preformatted text. Text that is enclosed in the pre element usually retains spaces and line breaks. The text is also rendered as an equal-width font.
For more details, refer to http://www.w3school.com.cn/tags/tag_pre.asp
, which means that the carriage return and spaces contained in the pre tag are displayed correctly. Include what you entered in the page code. So if you use the pre element you need to write this:

<pre> text to output </pre>, instead:

<pre>
Text to output
</pre> the latter The whitespace before the text will also be displayed. Unless you really want this:)
2. Replace the text content. The
carriage return and spaces are not displayed correctly because they differ in their representations. The carriage return entered in textarea is the character "\ R", and the carriage return (line break) in the HTML is "<br/>". The space entered in the
TextArea is blank "" and a space in the HTML is "&nbsp;". It is certainly not displayed correctly. Well, now that we know the reason, there's a second solution. The
is ok as long as we replace the corresponding "element" in the input text with the HTML. So the following line of code solves the problem:

Text to output. ReplaceAll ("", "&nbsp;"). ReplaceAll ("\ R", "<br/>"); Wait a minute. There's a little bit of a problem here. Replace a space with a "&nbsp;" The spaces still look less. If you like, you can replace it with 2.

Finally, in addition to the carriage return and white space, there are many blank words such as tab and so on, if you like can be processed together ^_^

Finally, if the original text is a long line, after using the pre tag will not wrap. The results page appears with a horizontal scroll bar. Do not know whether there is a good solution?
and the text that was processed by the second method is displayed in the <p> tab to show normal.

Line wrapping for Java pages

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.