Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.xml for jstl

Tags:

java

jsp

jstl

I tried codes with jstl. The exception is

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

I am using eclipse. I added jstl.jar and standard.jar. What should I give in web.xml now? I don't know what to give in <taglib>.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<c:forEach var = "userName" items = "${name}"> 
<tr> 
<td>${userName}</td>

 </tr>
 </c:forEach>   

</body>
</html>
like image 845
Sumithra Avatar asked Dec 14 '10 09:12

Sumithra


People also ask

What is Taglib in Web XML?

If you want to redistribute your tag files or implement your custom tags with tag handlers written in Java, you must declare the tags in a tag library descriptor (TLD). A tag library descriptor is an XML document that contains information about a library as a whole and about each tag contained in the library.

What is JSTL XML tags?

The JSTL XML tags are used for providing a JSP-centric way of manipulating and creating XML documents. The xml tags provide flow control, transformation etc. The url for the xml tags is http://java.sun.com/jsp/jstl/xml and prefix is x. The JSTL XML tag library has custom tags used for interacting with XML data.

Does Tomcat come with JSTL?

You can dive into our beloved stackoverflow.com to find out that Tomcat doesn't include JSTL,not even in Tomcat 8, in spite that they have an implementation of the JSP Standard Tag Library (JSTL) specification, versions 1.0, 1.1 and 1.2.

What is JSTL in HTML?

JSTL stands for JSP Standard Tag Library. JSTL is the standard tag library that provides tags to control the JSP page behavior. JSTL tags can be used for iteration and control statements, internationalization, SQL etc.


2 Answers

This can happen if you either downloaded the ancient JSTL 1.0 which has a different URI, or you placed the JAR's in the wrong place (i.e. not in /WEB-INF/lib or anywhere in webapp's runtime classpath).

Ensure that you download the right version and put the JAR(s) in /WEB-INF/lib. For a webapplication whose web.xml is declared as Servlet 2.5, you need to download just JSTL 1.2 as jstl-1.2.jar. For a Servlet 2.4 webapplication, you need to download JSTL 1.1 as jstl.jar and standard.jar.

You don't need to extract the JAR's. You also don't need to modify the web.xml as some poor online tutorials suggest. Just drop JAR(s) in runtime classpath, declare the taglib in JSP and that's it.

like image 96
BalusC Avatar answered Oct 03 '22 16:10

BalusC


There is no need to make an entry of jstl.jar or standard.jar inside web.xml if the jars are kept in the lib directory inside WEB-INF. The container by default looks into the lib directory of WEB-INF

like image 24
Tushar Avatar answered Oct 03 '22 15:10

Tushar