First create the tag support class called RoundPrice: package com.sams.learnweblogic7.tagLibClasses; import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import com.sams.learnweblogic7.utils.*; /** * This class displays the amount in the rounded format. */ public class RoundPrice extends TagSupport{ private double bookPrice; public int doStartTag() { System.out.println("Inside the tag in dostart"); try{ JspWriter out = pageContext.getOut(); bookPrice = getBookPrice(); out.println(Utility.getRoundedAmount(bookPrice)); } catch(Exception e){ System.out.println("Please check your code"); e.printStackTrace(); } finally{ return(SKIP_BODY); } } public void setBookPrice(double moneyVal){ this.bookPrice = bookPrice; } public double getBookPrice(){ return bookPrice; } } Now create the entry in customTagTLD.tld: <tag> <name>RoundPrice</name> <tagclass>com.sams.learnweblogic7.tagLibClasses.RoundPrice</tagclass> <bodycontent>empty</bodycontent> </tag> Add the following attribute tag in the web.xml file, inside the existing tagLib attribute: <attribute> <name>RoundPrice</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> Next you need to alter the JSP. The book price will be calculated via the following: double totBook1Price = book1Qty * book1.getBookPrice(); double totBook2Price = book2Qty * book2.getBookPrice(); double totBook3Price = book3Qty * book3.getBookPrice(); double grandTotal = totBook1Price + totBook2Price + totBook3Price; Now the code to display the table in the ViewCartJsp.jsp will look as follows: <wl:cache name="commonHeader" scope="session"> </wl:cache> <CENTER><B>Your Shopping Cart Contains:</B></CENTER><BR> <TABLE width = 100%> <TR> <TH> </TH> <TH>Book Name and description</TH> <TH>Book Price</TH> <TH>Qty</TH> <TH>Total for each book</TH> </TR> <wl:cache name="book1Vars" scope="session"></wl:cache> <TD align='center'><%=book1Qty%></TD> <TD align='center'> $<ctt:RoundPrice BookPrice="<%=totBook1Price%>"/> </TD> </TR> <wl:cache name="book2Vars" scope="session"></wl:cache> <TD align='center'><%=book2Qty%></TD> <TD align='center'> $<ctt:RoundPrice BookPrice="<%=totBook2Price%>"/> </TD> </TR> <wl:cache name="book3Vars" scope="session"></wl:cache> <TD align='center'><%=book3Qty%></TD> <TD align='center'> $<ctt:RoundPrice BookPrice= "<%=totBook3Price%>"/></FONT> </TD> </TR> <TR bgcolor='#eeeeee'> <TD> </TD> <TD> </TD> <TD> </TD> <TD> </TD> <TD align='left'> <B>Total=$<ctt:RoundPriceBookPrice="<%=grandTotal%>"/></B> </TD> </TR> </TABLE> <p align ="left"> <INPUT type="submit" name="buttonName" value="Empty Shopping Cart"> </p> |