JSP web.xml <jsp-config>标签使用详解

本文介绍了JSP配置中的&lt;jsp-config&gt;元素及其子元素&lt;taglib&gt;和&lt;jsp-property-group&gt;的使用方法。特别是&lt;jsp-property-group&gt;元素,它是JSP2.0新增的内容,用于指定一组JSP页面共有的属性,如EL语法的支持、脚本语法的支持、页面编码等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<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>GB2312</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 应用程式来说,Scriptlet 是个不乐意被见到的东西,因为它会使得HTMLJava 程式码交相混杂,对于程式的维护来说相当的麻烦,必要的时候,您可以在web.xml 中加上<script-invalid> 标签,设定所有的JSP 网页都不可以使用Scriptlet ,例如:
<web-app ..>
    ....
    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <script-invalid>true</script-invalid>
        </jsp-property-group>
    </jsp-config>
....
</web-app>
 


<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://java.sun.com/xml/ns/j2ee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"--> <!-- version="2.4">--> <web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5.xsd" version="5.0"> <display-name>howie2</display-name> <filter> <filter-name>hmvc</filter-name> <filter-class>com.howie.hmvc.DispatcherFilter</filter-class> </filter> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.jhtml</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.aj</url-pattern> </filter-mapping> <filter-mapping> <filter-name>hmvc</filter-name> <url-pattern>*.ar</url-pattern> </filter-mapping> <jsp-config> <taglib> <taglib-uri>asy</taglib-uri> <taglib-location>/WEB-INF/anshuyun.tld</taglib-location> </taglib> </jsp-config> <error-page> <error-code>404</error-code> <location>/error/404.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error/500.jsp</location> </error-page> <session-config> <session-timeout>20</session-timeout> <!-- <cookie-config> <secure>true</secure> </cookie-config> --> </session-config> <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <http-method>HEAD</http-method> <http-method>OPTIONS</http-method> <http-method>TRACE</http-method> </web-resource-collection> <au
03-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值