12. Learning Java: JSTL, part 3 – a rant

Sep 29th, 2010

In this hours, it comes tag files in JSTL. Creating tags and using those tags.

Inside web folder:  index.jsp

<%-- 
    Document   : index
    Created on : Sep 24, 2010, 7:30:10 PM
    Author     : JAVA
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<%@ taglib tagdir="/WEB-INF/tags/" prefix="Emp" %>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h2>Employee Details</h2>
        <table border="1">
            <Emp:Header col1="Eno" col2="Ename" col3="Salary" />
            <Emp:Data data1="1" data2="Satya" data3="1234.56"  />
            <Emp:Data data1="2" data2="Dhanu" data3="3241.32" />

<table>
        
    </body>
</html>

Inside web\WEB-INF\tags: Two files - Header.tag and Data.tag

<%-- 
    Document   : Data
    Created on : Sep 24, 2010, 7:42:58 PM
    Author     : JAVA
--%>

<%@tag description="put the tag description here" pageEncoding="UTF-8"%>
<%-- The list of normal or fragment attributes can be specified here: --%>

<%-- any content can be specified here e.g.: --%>
<%@ attribute name="data1" %>
<%@ attribute name="data2" %>
<%@ attribute name="data3" %>


<tr>
    <td>${data1}</td>
    <td>${data2}</td>
    <td>${data3}</td>

</tr>
<%-- 
    Document   : Header
    Created on : Sep 24, 2010, 7:41:39 PM
    Author     : JAVA
--%>

<%@tag description="put the tag description here" pageEncoding="UTF-8"%>
<%-- The list of normal or fragment attributes can be specified here: --%>
<%-- any content can be specified here e.g.: --%>

<%@ attribute  name="col1" %>
<%@ attribute  name="col2" %>
<%@ attribute  name="col3" %>

<tr>
    <th>${col1}</th>
    <th>${col2}</th>
    <th>${col3}</th>
</tr>

Output:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>

    <body>
        <h2>Employee Details</h2>

        <table border="1">
	<tr>
	    <th>Eno</th>
	    <th>Ename</th>
	    <th>Salary</th>

	</tr>


	<tr>
	    <td>1</td>
	    <td>Satya</td>
	    <td>1234.56</td>

	</tr>
		    

	<tr>
	    <td>2</td>
	    <td>Dhanu</td>
	    <td>3241.32</td>

	</tr>

	</table>
     
    </body>
</html>


Just got a good short article at SitePoint. Need to read that.

Error coming:
Note: D:\java\Sep24\build\generated\src\org\apache\jsp\index_jsp.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
I am aware of this a little. Solutions was discussed in Generics. Need to study that.

 
  1. No comments yet.
Comments are open for an year period. Please, write here on Facebook page.