JSTL tag library is a component technology for J2EE applications handled by Sun microsystems. They are a package of simple tag libraries useful for buiding dynamic jsps. They are easily understandabe and useful for non programmers which can be used as alternative for the scriptlets:
Types of JSTL tags:
c - core
fmt - formatting
x - XML processing
sql - db access
fn - functions
Types of C tags:
1. <c:set var="name" value="sam" />
2. <c:out value="${name}" />
3. <c:choose>
<c:when test="${}">
....
</c:when>
<c:otherwise>
....
</c:otherwise>
</c:choose>
4. <c:if test="${name eq 'same'}" ></c:if>
5. <c:import url="src/main.jsp" />
6. <c:import url="src/main.jsp" >
<c:param var="id" value="1001" />
</c:import>
7. <c:url var="main" url="src/main.jsp"/>
8. <c:redirect url="${src/redirect.jsp}" />
etc..
fmt tags:
1. <fmt:setBundle var="storeText" basename="${jspStoreDir}StoreText" /> - set it in a scoped variable
2. <fmt:message bundle="${storeText}" key="errMsg" var="errMsg" />
3. <fmt:setLocale value="${CommandContext.locale}" /> - set defualt locale value for the scope
4. <fmt:bundle basaename="${jspStoreDir}StoreText" prefix="label" /> - sets localization context
5. <fmt:param > EX:
<fmt:message key="errMsg">
<fmt:param userId="${userId}" />
</fmt:message>
6.<fmt:formatNumber type="currency" value="2.5" />
7. <fmt:formatDate var="bday" value="05/01/99" pattern="MM/DD/YY" />
8. <fmt:formatNumber var="rate" value="400" pattern="###.##" type="number" />
etc..
SQL tags:
For executing SQl queries
1. <sql:query var="users">
SELECT * FROM USERS WHERE NAME="sam"
</sql:query>
2. <sql:update var=count>
UPDATE USERS SET LASTNAME="SSS" WHERE users_id=1001
</sql:update>
3. sql:param EX:
<sql:update var=count>
UPDATE USERS SET LASTNAME="SSS" WHERE users_id=?
<sql:param value="1001" />
</sql:update>
4. <sql:transaction>
<sql:update sql="INSERT INTO USERS VALUES(1002, 'XXX', 'YYY')" />
</sql:transaction>
etc..
xml tags:
1. <x:parse> - Fo parsing XML content
2. <x:out> printing xpath expression
3. <x:set> -
4. <x:if>
5. <x:choose>
etc..
fn tags
1. fn:replace (string, beforeStr, afterStr)
2. fn:subString (string, beginindex, endIndex)
3. fn:length(string)
4. fn:escapeXml(string)
5.fn:containsIgnoreCase(string, subString)
etc..
wcbase:useBean tag
<wcbase:useBean id=usersDataBean className=com.ibm.commerce.myBeans.MyDataBean scope="page">
<c:set property="my_id" value="1001" target="${usersDataBean}" />
</wcbase:useBean>
Other way of inoking databean from jsp is using jsp:useBean tag
<jsp:useBean id="mydataBean" className="com.ibm.myBeans.MyDataBean" scope="page">
<% com.ibm.commerce.beans.DataBeanManager.actiate(mydataBean,request,response);%>
<jsp:useBean>
Types of JSTL tags:
c - core
fmt - formatting
x - XML processing
sql - db access
fn - functions
Types of C tags:
1. <c:set var="name" value="sam" />
2. <c:out value="${name}" />
3. <c:choose>
<c:when test="${}">
....
</c:when>
<c:otherwise>
....
</c:otherwise>
</c:choose>
4. <c:if test="${name eq 'same'}" ></c:if>
5. <c:import url="src/main.jsp" />
6. <c:import url="src/main.jsp" >
<c:param var="id" value="1001" />
</c:import>
7. <c:url var="main" url="src/main.jsp"/>
8. <c:redirect url="${src/redirect.jsp}" />
etc..
fmt tags:
1. <fmt:setBundle var="storeText" basename="${jspStoreDir}StoreText" /> - set it in a scoped variable
2. <fmt:message bundle="${storeText}" key="errMsg" var="errMsg" />
3. <fmt:setLocale value="${CommandContext.locale}" /> - set defualt locale value for the scope
4. <fmt:bundle basaename="${jspStoreDir}StoreText" prefix="label" /> - sets localization context
5. <fmt:param > EX:
<fmt:message key="errMsg">
<fmt:param userId="${userId}" />
</fmt:message>
6.<fmt:formatNumber type="currency" value="2.5" />
7. <fmt:formatDate var="bday" value="05/01/99" pattern="MM/DD/YY" />
8. <fmt:formatNumber var="rate" value="400" pattern="###.##" type="number" />
etc..
SQL tags:
For executing SQl queries
1. <sql:query var="users">
SELECT * FROM USERS WHERE NAME="sam"
</sql:query>
2. <sql:update var=count>
UPDATE USERS SET LASTNAME="SSS" WHERE users_id=1001
</sql:update>
3. sql:param EX:
<sql:update var=count>
UPDATE USERS SET LASTNAME="SSS" WHERE users_id=?
<sql:param value="1001" />
</sql:update>
4. <sql:transaction>
<sql:update sql="INSERT INTO USERS VALUES(1002, 'XXX', 'YYY')" />
</sql:transaction>
etc..
xml tags:
1. <x:parse> - Fo parsing XML content
2. <x:out> printing xpath expression
3. <x:set> -
4. <x:if>
5. <x:choose>
etc..
fn tags
1. fn:replace (string, beforeStr, afterStr)
2. fn:subString (string, beginindex, endIndex)
3. fn:length(string)
4. fn:escapeXml(string)
5.fn:containsIgnoreCase(string, subString)
etc..
wcbase:useBean tag
<wcbase:useBean id=usersDataBean className=com.ibm.commerce.myBeans.MyDataBean scope="page">
<c:set property="my_id" value="1001" target="${usersDataBean}" />
</wcbase:useBean>
Other way of inoking databean from jsp is using jsp:useBean tag
<jsp:useBean id="mydataBean" className="com.ibm.myBeans.MyDataBean" scope="page">
<% com.ibm.commerce.beans.DataBeanManager.actiate(mydataBean,request,response);%>
<jsp:useBean>
No comments:
Post a Comment