Example & Tutorial understanding programming in easy ways.

How is Taglib Directive used in JSP?

Explanation:
Taglib directive is used to define the tag library which is a collection of tags. A Tag library can be a standard(pre-defined) or a custom(user-defined) one. The "prefix" attribute is a must for custom as well as standard tags in jsp.

You must use a taglib directive before you use the custom tag in a JSP page. You can use more than one taglib directive in a JSP page, but the prefix defined in each must be unique.

JSP Syntex:  

<%@ taglib uri="xyz" prefix="xyz"%>

Example: <%@ taglib uri="http://java.my.com/jsp/jstl/core" prefix="c" %>

NOTE: As shown above, taglib in JSP has only two attributes, uri and prefix.

Exanple: Taglib Directive in JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

pageEncoding="ISO-8859-1"%>

<%@ taglib uri="http://java.MY.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transi...//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Taglib in JSP Example</title>

</head>

<body>

<c:set var="test" value="Taglib Directive in JSP"></c:set>

<c:out value="${test}"></c:out>

</body>

</html>

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!