标签库

 

 

import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.jsp.*;
public class getSumprice extends TagSupport {
 Book nbk=new Book();
 Iterator list=null;
 float sumprice=0;
 String bookname=null;
 float singleprice=0;
 
 public void setList(List list){
  this.list=list.iterator();
 }
 
 public getSumprice(){
  
 }
 
 public int doStartTag() throws JspTagException{
  return EVAL_BODY_INCLUDE;
 }
 
 public int doEndTag() throws JspTagException{
  sumprice=0;
  while(list.hasNext())
  {
   
   nbk=(Book)list.next();
   bookname=nbk.getName();
   singleprice=nbk.getPrice();
   try
   {
    pageContext.getOut().println(bookname+"<input type='checkbox'"+ "name='"+bookname+"' value='"+singleprice+"' /></td>"+"<br>");
       pageContext.getOut().println("你购买书的价格为:"+singleprice+"<br>");
   }
   catch(IOException e)
   {
    e.printStackTrace();
   }
   sumprice+=singleprice;
   try
   {
    pageContext.getOut().println("书的总价格为:"+sumprice);
   }
   catch(IOException e)
   {
    e.printStackTrace();
   }
  }
  return EVAL_PAGE;
 }
 
}

上面 是自定义的标签,在标签库中添加就可以了

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
    
<tlib-version>1.0</tlib-version>
    
<jsp-version>1.2</jsp-version>
    
<short-name>sum</short-name>
    
<tag>
        
<name>startSum</name>
              
<tag-class>shop.getSumprice</tag-class>
        
<body-content>emety</body-content>
        
<attribute>
            
<name>list</name>
            
<required>true</required>
            
<rtexprvalue>true</rtexprvalue>
        
</attribute>
    
</tag>
</taglib>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值