JSTL-JSP Standard TagLibrary -Tutorial

 

JSTL  (JSP standard Tag Library)

 

e-trainings-JSTL-JSP Standard TagLibrary -Tutorial


JSPHome


The purpose of Tag Library is, without having any coding knowledge one should be able to
write, debug, and trace the code.
 

JSTL technology  adapted from cold fusion.

Tags available in this library(version 1.2) are as follows..

1. core
    prefix: c
   
Syn:   

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


2. sql
connecting to database for CRUD operations.
      prefix: sql
   
Syn:   

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


3. xml → parsing, reading, querying XML files.
    prefix: x
    Syn:   

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

    
4. format 
Internationalization (i18n)
    prefix: fmt
   
Syn:     

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


5. functions
creating and invoking user defined functions.
      prefix: fn
   

    Syn:  

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

 

 

Types of  JSTL Core Tags

 
<c:set>
<c:remove>

	 <c:if>			|
	 <c:choose>		| Conditional
	 <c:when>		|
	 <c:otherwise>		|

	 <c:forEach>	        | Iteration	
	 <c:forTokens>	        |

	 <c:import>		|
	 <c:param>		|
	 <c:redirect>	        | URL management
	 <c:url>		|
		
 	
	 <c:out>		| General purpose
	 <c:catch>		|


 <c:set    var="a"     value="abc" />

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

The Dollar sign($)  and brace will be familiar ground for Perl programmers. In JSTL  and JSP-2, it is known as EL ( Expression Language). To consider another example, In servlet  and JSP, we write:


String s = request.getParameter("text1");


The same job is done in JSTL by:

<c:set  var="s" value="${param.text1}" >

demo.jsp


<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"  %>
<html>  
<body>  
<c:set var="s"  value="${param.text1}" />  
We welcome<br>  
<c:out      value="${s}" />  
</body>  
</html>


demo1.jsp <%@ page contentType="text/html" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %> <html> <body bgcolor=lightblue> <form method= "post" action="demo1.jsp"> 
 
 NAME <input  type="text"  name="text1"><br>
 PLACE<input  type="text"  name="text2"><br>
      <input  type="submit" type="submit">
 </form>

 NAME:<c:out    value="${param.text1}"  /><br>
 PLACE:<c:out   value="${param.text2}"  />
 
</body>
</html>


player.java
 
package ourbeans;
 
public class Person{ 
 
 String         name;
 String         city;
 String         email;
 
public player(){
    name  = " ";
    city  = " ";
    email = " ";  
 }

 public void setName(String a){
   name=a;
 }

 public void setCity(String b){
   city=b;
 }

 public void setEmail(String c){
   email=c;
  }

 public String     getName(){
     return  name;
 }

 public String    getCity(){
     return  city;
 }

 public String  getEmail(){
     return    email;
 }

}

 
demo2.jsp

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"  %>

<html>
<body>
<form method= "post" action="demo2.jsp">

<jsp:useBean id="bean1" class="ourbeans.person">
<jsp:setProperty name="bean1" property="*"   />
</jsp:useBean>

Name <input   type="text"   name="name"><br>
City<input  type="text"    name="city"><br>
Email<input   type="text"    name="email"><br>
    <input   type="submit" type="submit">

</form>

Name: <c:out value="${bean1.name}"  /><br>
City: <c:out value="${bean1.city}"  /><br>
Email: <c:out value="${bean1.email}"  />

</body>  
</html>

 

 

Comments

Popular posts from this blog

Using javascript pass form variables to iframe src

Creating a new PDF by Merging PDF documents using TCPDF

Import excel file into mysql in PHP