日期:2014-05-16  浏览次数:20474 次

JSP遍历所有数据标签与转义标签 --->张国亮总结心得第五季(完结篇)
[java] view plaincopyprint?
  1. <SPAN style="BACKGROUND-COLOR: #ffffff; COLOR: #009900">标签处理类:
  2. </SPAN>
  3. <SPAN style="BACKGROUND-COLOR: #ffffff">package com.csdn.web.example;
  4. import java.io.IOException;
  5. import java.lang.reflect.Array;
  6. import java.util.ArrayList;
  7. import java.util.Collection;
  8. import java.util.HashMap;
  9. import java.util.Iterator;
  10. import java.util.Map;
  11. import javax.servlet.jsp.JspException;
  12. import javax.servlet.jsp.tagext.SimpleTagSupport;
  13. publicclass ForEachAll extends SimpleTagSupport{
  14. private Collection collection;
  15. private String var;
  16. private Object items;
  17. publicvoid setVar(String var) {
  18. this.var = var;
  19. }
  20. publicvoid setItems(Object items) {
  21. this.items = items;
  22. }
  23. @Override
  24. publicvoid doTag() throws JspException, IOException {
  25. //判断是否是Map 下面的三个判断可以在doTage()方法中也可以在setItems()方法中
  26. if(itemsinstanceof Map){
  27. //这里要把jsp页面传进来的属性强转为Map类型,不能new HashMap