1.s:generator标签概述
[table]
|属性名|是否必须|类型|说明|
|converter|False|org.apache.struts2.util.IteratorGeneratorConverter|将字符串转换为Object对象的类实例|
|count|False|Integer|指定最大分割的数量|
|separator|True|String|指定分隔符|
|val|True|String|指定要分割的字符串|
|var|False|String|将结果放到Page上下文中|
[/table]
2.新建Action实例
3.新建JSP文件
4.修改struts.xml文件
5.运行结果:
[img]http://dl.iteye.com/upload/attachment/380491/62d14546-dff2-35d9-ab4f-ff98a52d2ded.png[/img]
[table]
|属性名|是否必须|类型|说明|
|converter|False|org.apache.struts2.util.IteratorGeneratorConverter|将字符串转换为Object对象的类实例|
|count|False|Integer|指定最大分割的数量|
|separator|True|String|指定分隔符|
|val|True|String|指定要分割的字符串|
|var|False|String|将结果放到Page上下文中|
[/table]
2.新建Action实例
package com.wl.control.tagsAction;
import com.opensymphony.xwork2.ActionSupport;
public class ShowGeneratorList extends ActionSupport {
private String nameList="张三,李四,王五";
public String getNameList() {
return nameList;
}
public void setNameList(String nameList) {
this.nameList = nameList;
}
@Override
public String execute() throws Exception {
return "showgeneratorlist";
}
}
3.新建JSP文件
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<s:generator separator="," val="nameList">
<s:iterator>
<s:property/>
<br/>
</s:iterator>
</s:generator>
</body>
</html>
4.修改struts.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="Struts2.1" extends="struts-default">
<action name="showgeneratorlist" class="com.wl.control.tagsAction.ShowGeneratorList">
<result name="showgeneratorlist">/controlTags/showgeneratorlist.jsp</result>
</action>
</package>
</struts>
5.运行结果:
[img]http://dl.iteye.com/upload/attachment/380491/62d14546-dff2-35d9-ab4f-ff98a52d2ded.png[/img]