您的位置:首页 > Web前端 > JavaScript

使用JSTL中遇到的EL报错问题

2007-01-04 01:34 627 查看
今天自己想玩一把JSTL可惜老出状况。所以自己就去网上找喽!
网上给了一个答案,还不错:
解决方案1:
修改web.xml文件
<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">
把上面那个改为这个:
<!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>
对。我试了一下,不错,是可以运行。但是还有一个问题:EL表达示他不运行啊!好像被忽略掉了一样。
下面给一个例子。自己运行一下看看就明白了。
myjsp.jsp文件
<%@ page contentType="text/html;charset=GB2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'myjsp.jsp' starting page</title>
</head>

<body>

This is my JSP page. <br>
<table>
<tr>
<td>${true and true}</td>
<td> <c:set var="user" value="zhangsan" scope="session"/></td>
<td><c:out value="${true and true}"/></td>
<td>变量为</td>
<td><c:out value="4545"/></td>
</tr>
</table>
</body>
</html>

web.xml文件
<!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>

你运行以后的结果了:它变成什么样了哦?
This is my JSP page.

${true and true}true变量为4545
输出 的是这个样子
而我们要的是这个结果:
This is my JSP page.

truetrue变量为4545
所以,以上的方法有一些些问题哦~!

解决方案2:
再给我们的web.xml
先把我们从apache的网站上下的文件解压
然后把jakarta-taglibs-standard-1.1.2/jakarta-taglibs-standard-1.1.2/tld里面的那几个标签copy过来到你的工作区。
web.xml改成这样:
<?xml version="1.0" encoding="ISO-8859-1"?>
<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">
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
<taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
<taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
<taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
<taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
</jsp-config>

</web-app>
好啦!改成这样就可以在jsp里面了较好的使用他们了!
大家加油啊!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: