Struts框架 自定义标签类文件(checkout所选书籍及其价钱)

来源:互联网 发布:遗传算法特征选择代码 编辑:程序博客网 时间:2024/06/07 23:41

package com.yourcompany.struts.model;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class app extends TagSupport {
 
    private Book[] name = null;
    double money=0;
 
 public Book[] getName() {
  return name;
 }

 public void setName(Book[] name)
 {
  this.name = name;
 }

 public int doStartTag() throws JspException
{
  JspWriter out = pageContext.getOut();
  money=0;
  for(int i=0;i<name.length;i++)
  {
   try
  {
    
     out.println("<LI>"+" "+name[i].getIsbn()+" "+name[i].getName()+" "+name[i].getPrice()+"$");
    
     money = money +  Integer.parseInt(name[i].getPrice());
  } catch (IOException e)
  {
   e.printStackTrace();
  }
     
  }
  
  try
  {   out.println("<br>");
   out.println("Total:"+money);
   
  } catch (IOException e)
  {  
   e.printStackTrace();
  }
  return SKIP_BODY;
 }

}