背景:
公司搭建的工程web.xml版本为2.3 在jsp中不能使用el表达式
解决方案:
①修改web.xml版本为2.4 / 2.5 / 3.0 当修改为2.3以上版本时,可以在页面中直接使用el表达式
(不推荐,不能因为个人项目中出现的问题,而修改公司框架结构) ②在jsp页面中添加el表达式的显示支持 isELIgnored="false"
例 :<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false" %>
2.3版本的jsp页面是不支持这个属性提示的,报黄线属于正常
这时虽然可以使用el表达式,但与c标签结合使用时,会出现如下异常
According to TLD or attribute directive in tag file, attribute items does not accept any expressions
查阅资料,貌似是c标签在2.3下不能与el一起使用
解决方案:使用c标签的扩展库
<taglib>
<taglib-uri>/c-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
上面的代码是在web.xml中配置的,当然你也可以直接在jsp页面中配置
<%@ taglib uri="/WEB-INF/c-rt.tld" prefix="c"%> 或
<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>
这样就可以在c标签中使用el表达式了
下面是2.3 2.4 2.5 版本的头信息
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>
...
</web-app>
Servlet 2.4
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:web="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
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-app>
Servlet 2.5
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
version="2.5">
...
</web-app>
补充:
如果在web.xml中配置tld标签的话 2.3版本与 后面的版本写法是不同的
2.3 存在taglib这个节点
<taglib>
<taglib-uri>/c-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>
2.4/2.5/3.0 标签节点包含在 jsp=config中
<jsp-config>
<taglib>
<taglib-uri>/custom-tags</taglib-uri>
<taglib-location>/WEB-INF/custom-tags.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://onezero.com.cn/view/jsp/blockview</taglib-uri>
<taglib-location>/WEB-INF/blockview.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-html</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-bean</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/struts-logic</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/functions</taglib-uri>
<taglib-location>/WEB-INF/fn.tld</taglib-location>
</taglib>
<jsp-property-group>
<description>html encode</description>
<display-name>JSPConfiguration</display-name>
<url-pattern>*.html</url-pattern>
<el-ignored>true</el-ignored>
<page-encoding>UTF-8</page-encoding>
<scripting-invalid>false</scripting-invalid>
<include-prelude></include-prelude>
<include-coda></include-coda>
</jsp-property-group>
</jsp-config>