我在使用jstl编程的时候,使用了EL表达式,但是在使用的过程中,遇到了如下几个问题:(使用的环境是Eclipse)
1、纯粹的EL表达式解析不出来,但是当把EL表达式放在jstl的核心库的c:out标签中时,却能够显示出来。
如:1+1=${1+1} //其显示结果为1+1=${1+1}
如果写为:1+1=<c:out value="${1+1}"> //其显示结果为1+1=2
2、web.xml配置文件中如果我写成:<web-app id="WebApp_ID" version="2.4" 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">,在写下面的<taglib>标签是就会报错,如果将<taglib>标签放置在<jsp-config>标签中时,在要引用引入的标签时,能够只能提示,但是不能正常执行,其要报错。所以我只能够不要<jsp-config>标签,然后将web.xml中的<web-app>写成:<web-app id="WebApp_ID">,这样虽然引用标签能够正常执行,但是就会出现前面第一点的错误。
我是struts初学者,希望各位大虾能够给我帮助,不胜感激!!!!
1、纯粹的EL表达式解析不出来,但是当把EL表达式放在jstl的核心库的c:out标签中时,却能够显示出来。
如:1+1=${1+1} //其显示结果为1+1=${1+1}
如果写为:1+1=<c:out value="${1+1}"> //其显示结果为1+1=2
2、web.xml配置文件中如果我写成:<web-app id="WebApp_ID" version="2.4" 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">,在写下面的<taglib>标签是就会报错,如果将<taglib>标签放置在<jsp-config>标签中时,在要引用引入的标签时,能够只能提示,但是不能正常执行,其要报错。所以我只能够不要<jsp-config>标签,然后将web.xml中的<web-app>写成:<web-app id="WebApp_ID">,这样虽然引用标签能够正常执行,但是就会出现前面第一点的错误。
我是struts初学者,希望各位大虾能够给我帮助,不胜感激!!!!
吗?
该引用的都引用了
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">
我用这个,貌似你那个写的不对,搜搜看看
而你给出的1+1= <c:out value="${1+1}"> 能够解析,这就说明不是EL不能解析的问题了。估计是你的web.xml配置有问题吧。没看明白你问题中的关于<taglib>那部分说的是什么意思。
<taglib>引入的标签时报错。
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">而 2.5 规范是这样的:<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">2.4 的是 ns/j2ee,而 2.5 的是 ns/javaee
<web-app version="2.5" 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">
<jsp-config>
<!--定义标签库-->
<taglib>
<!--确定标签库的URI-->
<taglib-uri>/tags/test.tld</taglib-uri>
<!-- 确定标签库定义文件的位置 -->
<taglib-location>/WEB-INF/test.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/tags/test1.tld</taglib-uri>
<taglib-location>/WEB-INF/test1.tld</taglib-location>
</taglib>
</jsp-config>
你把配置发来看看,这我的,测试的
那里面没有jstl.jar包吧。
如果web.xml中不加<taglib>标签,那么要在jsp页面中使用一些标签库的话,还需要使用
<%@ taglib prefix="c" uri=""%>这个引用吗,如果要的话,uri的值该为什么呢?我现在将web.xml中
的<taglib>标签去掉后,并且把jsp页面中也没有用<%@ taglib prefix="c" uri=""%>,在该页面中则不能使用jstl的核心库标签?
该怎么弄啊 ?谢谢
你就不敢把配置发全点,让大家在这猜
javaee1.4要加taglib吧
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
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"> <welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/c.tld</taglib-uri>
<taglib-location>/WEB-INF/c-1_0.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/x.tld</taglib-uri>
<taglib-location>/WEB-INF/x-1_0.tld</taglib-location>
</taglib>
</jsp-config></web-app>
使用的jsp页面如下:
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%>
<%@ page import="java.util.*,jstl_com.User" %>
<%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
<%@ taglib prefix="x" uri="/WEB-INF/x.tld" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>测试jstl</title>
</head>
<body>
<h1>测试jstl</h1>
<hr/>
<li>显示普通字符串</li><br />
el显示teststr=${requestScope.teststr}<br />
jsp脚本显示teststr=<%= request.getAttribute("teststr")%><br />
jstl核心库表示:teststr=<c:out value="${teststr}" /><br />
配置文件写成那样,在执行该jsp页面时报错所<c:out>错误