zoukankan      html  css  js  c++  java
  • Java web中的web-xml中标签定义之jsp-config

    <jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素。

    其中<taglib>元素在JSP 1.2时就已经存在;而<jsp-property-group>是JSP 2.0 新增的元素。
    <jsp-property-group>元素主要有八个子元素,它们分别为:
    1.<description>:设定的说明;
    2.<display-name>:设定名称;
    3.<url-pattern>:设定值所影响的范围,如:/CH2 或 /*.jsp;
    4.<el-ignored>:若为true,表示不支持EL 语法;
    5.<scripting-invalid>:若为true,表示不支持<% scripting %>语法;
    6.<page-encoding>:设定JSP 网页的编码;
    7.<include-prelude>:设置JSP 网页的抬头,扩展名为.jspf;
    8.<include-coda>:设置JSP 网页的结尾,扩展名为.jspf。
    一个简单的<jsp-config>元素完整配置:
    <jsp-config>
        <taglib>
            <taglib-uri>Taglib</taglib-uri>
            <taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location>
        </taglib>
        <jsp-property-group>
            <description>Special property group for JSP Configuration JSP example.</description>
            <display-name>JSPConfiguration</display-name>
            <url-pattern>/jsp/* </url-pattern>
            <el-ignored>true</el-ignored>
            <page-encoding>UTF-8</page-encoding>
            <scripting-invalid>true</scripting-invalid>
            <include-prelude>/include/prelude.jspf</include-prelude>
            <include-coda>/include/coda.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>


    其实在web.xml中并不是所有的属性都会用上的,例如下面的例子:

    <jsp-config>
    <jsp-property-group>
    <url-pattern>*.jsp</url-pattern>
    <page-encoding>UTF-8</page-encoding>
    <trim-directive-whitespaces>true</trim-directive-whitespaces>
    </jsp-property-group>
    </jsp-config>

    jsp中会经常使用到使用jsp标签和jstl的标签,比如<%@ page ..%>, <%@ taglib ...%>, <c:forEach....%>, 尤其是循环标签,在jsp最终输出的html中会产生大量的空行,使得性能降低。最方便的解决方法是在web.xml 中添加以下设置

    解决办法有两种

          1,在web.xml中

               <jsp-property-group>

                 <url-pattern>*.jsp</url-pattern>

                 <trim-directive-whitespaces>true

                     </trim-directive-whitespaces>

                </jsp-property-group>

          2,在每个jsp文件头部添加

                <%@ page trimDirectiveWhitespaces="true"%>

  • 相关阅读:
    Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)
    Educational Codeforces Round 79 (Rated for Div. 2)
    Codeforces Global Round 6
    Codeforces Round #608 (Div. 2)
    Codeforces Round #606 (Div. 2)
    Codeforces Round #603 (Div. 2)
    Educational Codeforces Round 77 (Rated for Div. 2)
    洛谷 P3805 【模板】manacher算法
    HDU 1671 Phone List [字典树]
    2019牛客暑期多校训练营(第一场)E.ABBA
  • 原文地址:https://www.cnblogs.com/burns/p/7440698.html
Copyright © 2011-2022 走看看