Remove blank lines when JSP generates HTML

Source: Internet
Author: User

Developers who use JSP know that the HTML generated after JSP compilation contains a large number of blank lines. These blank lines are generally not in the way, which at most reduces the friendliness of search engines and the readability of HTML. However, when JSP is used to generate an XML file? If the xml header is not at the top of the first line, the strict parser will report an error, such as operabrowser.

This problem has plagued me for a long time, and I have used a lot of taglib, such as jstl labels. As a result, a large piece of bald white wasteland on my HTML page looks awkward. I have been searching for a solution in the search engine, but only the questioner has no solution. Today, I couldn't help searching for another one, and finally removed the blank lines left by JSP to better solve this problem.

In the past, Tomcat 5.x added a parameter to specify whether to remove spaces between behaviors and commands in the template text. This is a problem with the JSP compiler, which can only be completely solved by the compiler itself.

Tomcat 5.x version is required, that is, jsp2.0 and servlet2.4 specifications. Add the following configuration items in the web. xml configuration.

<Servlet>
<Servlet-Name> JSP </servlet-Name>
<Servlet-class> org. Apache. Jasper. servlet. jspservlet </servlet-class>
<Init-param>
<Param-Name> trimspaces </param-Name>
<Param-value> true </param-value>
</Init-param>

<Load-on-startup> 3 </load-on-startup>
</Servlet>

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.