可能一: web项目出现如上问题,据查是版本问题: 可能二: 最终查到问题是 jstl.jar 包在ide项目中有,但在tomcat发布的应用WEB-INF/lib下没有,这是工具发布项目的问题,复制一个jar包过去问题就解决了。 >>jstl.jar没有 使用jstl的文档,这里有篇文档: http://www.mularien.com/blog/2008/04/24/how-to-reference-and-use-jstl-in-your-web-application/ As a frequent contributor to the Spring Framework user forums, I have noticed a common trend among people new to Spring MVC – they really don’t understand how to use JSTL and EL in their Spring-driven JSPs. Although Spring MVC supports flexibility in choosing a view technology, in my [back of the napkin] estimate, at least 80% of the time it is paired with JSP and JSTL. Unfortunately, since JSP was pushed out about 4-5 years ago, a lot of the information that you find on the web is extremely dated, often going back to JSTL 1.0 syntax (or, gasp, using scriptlets!). In this article I’ll clear up the confusion around how to use JSTL with various app servers and webapp versions. Here’s a hint: if you can’t get a simple (non-Spring-related!) expression like ${2+2} to work, no expressions will work! (In a properly functioning servlet container, the prior expression should output “4″ on the page). I set out to take some common application server configurations, combine them with various flavors of JSP/JSTL support, and see what happened. The Importance of Servlet Version and web.xml Let us review the following reference table: JSP/Servlet VersionServlet Version JSP Version JSTL Version Java EE Version
What Does this mean to me? The most important thing is to figure out what version of the Java EE web stack (Servlet/JSP) you are using. There are 2 aspects that factor into this:
Here’s an example of what to look for in web.xml: <?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID"version="2.5"><display-name>web-app-25</display-name> ... </web-app>
You can see the ‘version=”2.5″‘ designation in here. This means that within this web application, we will be able to use JSP 2.1 and JSTL 1.2 features. OK, How do I use JSTL in my Page? A very common problem that I have seen with new Spring users is that they don’t understand how to reference the JSTL tag libraries on their pages. Important!: You need to identify the version of web application you are using first. Web Application v2.5 and v2.4 To use EL Expressions: You do not need <c:out>. Simply insert EL expressions onto the page: ${2+2} <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Web Application v2.3 To use EL Expressions: You do need <c:out>. Raw EL expressions on the page will not work. e.g. <c:out value=”${2+2}”> <%@taglib prefix="c" uri="http://java.sun.com/jsp/core" %>
What about the _rt Taglibs Like core_rt? The following type of URI will also work, in JSTL 1.2 and 1.1: <%@taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
However, this is not desired. You should never have to reference the _rt versions of taglibs (e.g. core_rt). Do I need to include a JSTL Implementation with my Web Application? Obviously, there are a lot of application servers out there. I tested this with the following:
Of these, JBOSS and Glassfish ship with JSTL implementations out of the box. Tomcat does not ship with a JSTL implementation. I have previously blogged about this here. I did not test other application servers, simply because these are the ones I most commonly see referenced in the Spring forums. Websphere is also used, but I didn’t have access to it (and, frankly, didn’t want to spend the 8 hours and tens of gigs of downloads it would take to install it ). Testing Methodology For those who are interested, here’s the testing methodology I used to come to the conclusions above. I created 6 web applications. The 6 web applications are as follows:
In each web application, I created 4 JSP pages with the following content: Some simple math: ${2+2} <br/> Some simple math with c:out: <c:out value="${2+2}"/> <br/> Some simple math with c2:out: <c2:out value="${2+2}"/> <br/>
You can see there are 3 tests in the page. The goal of the tests are as follows:
For each of the 4 JSP pages, I varied how the JSTL core taglib was declared:
In a typical scenario where the container supports JSP 2.0+, what you would expect to see is the following: Some simple math: 4 What Happens if You Have the Wrong Declarations Some of the errors you may get if you don’t have things declared right: On Tomcat org.apache.jasper.JasperException: /test_c2_jstl_core_taglib_decl.jsp(11,32) According to TLD or attribute directive in tag file, attribute value does not accept any expressions No JSTL implementation: org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application On JBOSS Since JBOSS also uses the Apache Jasper JSP compiler, the errors are basically exactly the same as those listed above. On Glassfish org.apache.jasper.JasperException: /test_c2_jstl_core_taglib_decl.jsp(11,32) PWC6236: According to TLD or attribute directive in tag file, attribute value does not accept any expressions |