jsp页面中的EL表达式不被解析的问题

来源:互联网 发布:淘宝28的哈士奇 编辑:程序博客网 时间:2024/05/16 08:56

jsp页面中的EL表达式不被解析的问题

Shane WEB应用 0Comments发表评论

在使用jsp的el表达式时,发现tomcat 5对其不解析。按原样输出如${items}.
原样把tomcat 的jsp例子拷过来还是如此。web.xml里和lib里的配置都配好了。找了很久才发现web.xml文件使用的是servlet 2.3版本的声明的问题。el在servlet 2.3中默认是不启用的。

servlet 2.3的

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE web-app
  PUBLIC ’-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN’
  ’http://java.sun.com/dtd/web-app_2_3.dtd’>

<web-app id=”WebApp_ID”>

tomcat自带的 servlet 2.4的。

<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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
    version=”2.4″>

把web.xml的声明部分改为2.4的即可。
还有就是如果使用了<taglib>标签就需要加<jsp-config>父标签。具体内容看jsp2.0和servlet2.4规范

<jsp-config>
<taglib>
<taglib-uri>/tags/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
</jsp-config>

     在使用jsp的el表达式时,发现tomcat 5对其不解析。按原样输出如${items}.
原样把tomcat 的jsp例子拷过来还是如此。web.xml里和lib里的配置都配好了。找了很久才发现web.xml文件使用的是servlet 2.3版本的声明的问题。el在servlet 2.3中默认是不启用的。

servlet 2.3的

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE web-app
  PUBLIC ’-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN’
  ’http://java.sun.com/dtd/web-app_2_3.dtd’>

<web-app id=”WebApp_ID”>

tomcat自带的 servlet 2.4的。

<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 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”
    version=”2.4″>

把web.xml的声明部分改为2.4的即可。
还有就是如果使用了<taglib>标签就需要加<jsp-config>父标签。具体内容看jsp2.0和servlet2.4规范

<jsp-config>
<taglib>
<taglib-uri>/tags/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
</jsp-config>


文章作者:Shane

本文地址:http://cookray.sinaapp.com/?p=5
版权所有 © 转载时必须以链接形式注明作者和原始出处!