import javax.servlet.jsp.tagext.TagSupport;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.jsp.*;
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;
}
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;
}
}




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


















