Tutorial :JSTL tag not translate in HTML



Question:

My imports :

  xmlns:c="http://java.sun.com/jstl/core"    xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"  

My JSTL Code :

  <h:outputLabel value="YESS" >    <fmt:formatNumber value="0.25" type="percent"></fmt:formatNumber>  

HTML generated code:

  <label>YESS</label>    <fmt:formatNumber value="0.25" type="percent"></fmt:formatNumber>  

The generated code show that the JSTL core is translate in HTML.
But the JSTL "fmt" is not translate in HTML.





More information:

    <fmt:ErrorInThisFunctionName value="0.25" type="percent" />    ===> generate an error  
  • I work on Tomcat 6


Solution:1

What Pierre said, and also,

Try xmlns:fmt="http://java.sun.com/jstl/fmt"

Check web.xml for

<web-app 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">  


Solution:2

suggestion:

  • check your TLD file.
  • check your header (DTD, attributes) in your web.xml


Solution:3

If you are using the normal JSP syntax and not the XML-based syntax try using

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>  


Solution:4

xmlns:c="http://java.sun.com/jstl/core"  xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"  

The URI for core taglib is invalid. It should be http://java.sun.com/jsp/jstl/core as per its TLD, with /jsp. The URI for format taglib is perfectly fine as per its TLD.

Does the core taglib work in any way? If it doesn't work as well, then it simply means that JSTL is not installed at all. Tomcat does not ship with JSTL by default. You need to download jstl-1.2.jar and put it in /WEB-INF/lib of your webapp. That's all. Do not extract the JAR file and put its loose contents (TLD files and so on) in the classpath as some poor tutorials suggests. It will only get worse. If you already did so, you should cleanup. Only putting the JSTL JAR in classpath is enough.


Solution:5

I had the exact same problem where I would basically declare and it wouldn't get translated into HTML (basically, instead of printing the variable, the entire c:out was printed in the html source). I had forgotten to add this dependency to maven:

        <dependency>              <groupId>taglibs</groupId>              <artifactId>standard</artifactId>              <version>1.1.2</version>          </dependency>  

(If the xml doesn't print, the groupId is taglibs, the artifactId is standard, and the version is 1.1.2


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »