Loading
 
What's Next: View All Tutorial →

How to add Tag Library to Spring MVC

In this article, you will learn how to add tag library Refer Spring MVC Hello World for base project setup.   1. Add Tag Library in the Dependency Library   <dependency> <groupId>taglibs</groupId>...

Published Date: 13/12/2014  Last Modified Date: 13/12/2014    New Post




In this article, you will learn how to add tag library

Refer Spring MVC Hello World for base project setup.
 

1. Add Tag Library in the Dependency Library

 
 <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>   
        </dependency>
        


2. Include tag uri in the JSP to use the tag library

 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>


Sample Jsp File:
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Spring MVC Helloworld</title>
    </head>
    <body>
        <h1>${greetingText}</h1>
        <h3>${welcomeText}</h3>
    <c:out value="${greetingText}"/>
</body>
</html>
 
 

3. Possible Issues & Solutions


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
 

4. Additional Reference


JSTL Functions to know more about fn tag

JSTL Core Tags to know more about c:tag
 

5. Download Project


Download project from google drive(7 KB)
Awaiting for Administrator approval





Tags: [30 28]

← Back to list


Related Post




×