首先,强烈建议你先去看一下struts提供的html-sample的所有例子。他里面有大部分标签的使用例子。
如下小例子:
ActionForm: testForm.javaimport java.util.*;
public class testForm extends ActionForm{
private ArrayList list = new ArrayList() ;
public void setList( ArrayList list ){
this.list = list ;
}
public ArrayList getList(){
return this.list ;
}
public void reset(){
list.add("a");
list.add("b");
list.add("c");
list.add("d");
}
}关于action和config.xml自己配置吧。我给出页面的例子。
<logic:iterate id="listItem" name="list">
<bean:write name="listItem"/>
</logic:iterate>
如下小例子:
ActionForm: testForm.javaimport java.util.*;
public class testForm extends ActionForm{
private ArrayList list = new ArrayList() ;
public void setList( ArrayList list ){
this.list = list ;
}
public ArrayList getList(){
return this.list ;
}
public void reset(){
list.add("a");
list.add("b");
list.add("c");
list.add("d");
}
}关于action和config.xml自己配置吧。我给出页面的例子。
<logic:iterate id="listItem" name="list">
<bean:write name="listItem"/>
</logic:iterate>
解决方案 »
- 求大数据量,并发访问比较大的解决方案
- 急求高手教小弟这些问题或给予相关资料``
- struts,问个简单的
- 在myeclipse中配置websphere的问题
- 各位推荐一下,哪种报表可以实现冻结表头合并单元格,谢谢!
- 用户要求这样的并发量,JBOSS能够满足需要吗?高分求救
- tomcat5.0.30安装时的奇怪问题?
- 如何实现点一个按钮就能打开IE浏览器,到指定的网站? :)(急)
- JBuilder9+Weblogic7+SQLServer2000开发EntityEJB,为什么看不到数据库中该有的表?
- 想用JTable读出Excel表中的数据 但是JTable就是不显示 求帮助
- ***散分求助***如何实现从实体bean查询结果返回为一张表格
- 马上给100分!帮我解决一下在字符串中含有中文时怎么算出它的长度?
id="foo" indexId="ctr">
<html:text name='<%= "surname[" + ctr + "]" %>'/>
</logic:iterate>
<head>
<title>表单定义</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@include file="../../../pub/css.jsp"%>
<script id="chromeless" src="/oa/front/economy_check/document/pz_chromeless_2.1.js"></script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<logic:equal name="DocumentForm" property="errors" value="dbExistError">
<Script language="javascript">
window.alert("您所填写的表单已经存在,请指定其他的英文名称!");
</script>
</logic:equal>
<html:form method="post" action="/createDocument.do?action=save" scope="request" onsubmit="return formCheck();">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td align="center" height="40" valign="bottom">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
<tr valign="top"><td>
<table width="98%" height="28" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="66%" height="28"> <img src="/OA/front/images/desk_top.gif" width="11" height="11" align="absmiddle"><strong><font color="#<%=UserSession.per_color15%>"> 表单定义</font></strong></td>
<td width="34%"><%@include file="../../../pub/toolsbar.jsp"%></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0" background="/OA/front/images/pointline.gif">
<tr>
<td height="1"></td>
</tr>
</table>
</td>
</tr>
<tr><td height="3"> </td></tr>
<tr>
<td align="center" valign="top" height="235">
<table width="88%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#<%=UserSession.per_color13%>">
<table id="columnDefineTable" width="100%" cellpadding="3" cellspacing="1">
<tr bgcolor="#<%=UserSession.per_color8%>">
<td colspan="8">
<html:radio property="documentType" value="0" onclick="changeDocumentType(this);">普通表单</html:radio> <html:radio property="documentType" value="1" onclick="changeDocumentType(this);">填空式表单</html:radio>
</td>
</tr>
<tr bgcolor="#<%=UserSession.per_color8%>">
<td width="20%" align="center">表单中文名</td>
<td width="27%" >
<html:text property="documentChName" maxlength="100" size="20" styleClass="input_g"/>
</td>
<td width="23%" align="center" >表单英文名</td>
<td width="30%" >
<html:text property="documentEnName" maxlength="100" size="20" styleClass="input_g"/>
</td>
</tr>
<tr id="textContentLableTR" bgcolor="#<%=UserSession.per_color8%>" style="display:none;">
<td height="2" colspan="4" align="center"> 定义文本内容 </td>
</tr>
<tr id="textContentTR" bgcolor="#<%=UserSession.per_color8%>" style="display:none">
<td height="2" colspan="4" align="center"> <html:textarea property="textContent" cols="65" rows="8"></html:textarea> </td>
</tr>
<tr bgcolor="#<%=UserSession.per_color8%>">
<td height="2" colspan="4" align="center"> 定义字段信息 </td>
</tr>
<tr bgcolor="#<%=UserSession.per_color8%>">
<td colspan="4"> <table width="100%"border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="2" align="center">字段名</td>
<td width="14%" rowspan="2" align="center" valign="bottom">类型</td>
<td width="10%" rowspan="2" align="center" valign="bottom">大小</td>
<td width="10%" rowspan="2" align="center" valign="bottom">默认值</td>
<td width="10%" rowspan="2" align="center" valign="bottom">可修改</td>
<td width="10%" rowspan="2" align="center" valign="bottom">必填项</td>
<td width="17%" rowspan="2" align="center" valign="bottom">查询项</td>
</tr>
<tr>
<td width="14%" align="center">中文</td>
<td width="15%" align="center">英文</td>
</tr>
for(int i = 0;i < 20;i ++)
{
String fieldChName = "fieldChName["+i+"]";
String fieldEnName = "fieldEnName["+i+"]";
String fieldType = "fieldType["+i+"]";
String fieldSize = "fieldSize["+i+"]";
String fieldDefaultValue = "fieldDefaultValue["+i+"]";
String isModify = "isModify["+i+"]";
String isNeed = "isNeed["+i+"]";
String isSelect = "isSelect["+i+"]";
%>
<tr bgcolor="#<%=UserSession.per_color8%>">
<td align="center">
<html:text property="<%=fieldChName%>" size="7" styleClass="input_g"/>
</td>
<td align="center">
<html:text property="<%=fieldEnName%>" size="7" styleClass="input_g"/>
</td>
<td align="center">
<html:select property="<%=fieldType%>" styleClass="input_g" onchange="typeChoice(this);">
<html:option value="varchar">文字</html:option>
<html:option value="text">文本</html:option>
<html:option value="int">整数</html:option>
<html:option value="float">浮点数</html:option>
<html:option value="datetime">日期</html:option>
<html:option value="time">时间</html:option>
<html:option value="append">附件</html:option>
<html:option value="singleChoice">单选</html:option>
<html:option value="multiChoice">多选</html:option>
</html:select>
</td>
<td align="center" id="<%=fieldSize%>TD">
<html:text property="<%=fieldSize%>" size="7" styleClass="input_g"/>
</td>
<td align="center" id="<%=fieldDefaultValue%>TD">
<html:text property="<%=fieldDefaultValue%>" size="7" styleClass="input_g"/>
</td>
<td align="center" id="openMoidSelectPage[<%=i%>]TD" colspan="2" style="display:none">
<input type="button" value="修改选择项" class="input_g" onclick="openModiPage('<%=i%>');">
</td>
<td align="center">
<html:select property="<%=isModify%>" styleClass="input_g">
<html:option value="true">是</html:option>
<html:option value="false">否</html:option>
</html:select>
</td>
<td align="center">
<html:select property="<%=isNeed%>" styleClass="input_g">
<html:option value="true">是</html:option>
<html:option value="false">否</html:option>
</html:select>
</td>
<td align="center">
<html:select property="<%=isSelect%>" styleClass="input_g">
<html:option value="true">是</html:option>
<html:option value="false">否</html:option>
</html:select>
</td>
</tr>
<%}%>
</table></td>
</tr>
</table></td>
</tr>
</table>
<html:textarea property="dataOfChoice" style="display:none"></html:textarea>
<table width="88%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td><br>
<html:submit value="提交" property="submitButton" styleClass="input_g"/>
<input type="reset" value="重置" class="input_g"/>
</td>
</tr>
</table>
</table></html:form>
</body>
</html:html>
package struts.caseManage.documentManage;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;
import java.io.*;
import java.util.*;public class DocumentForm extends ActionForm
{
private final ArrayList fieldChName = new ArrayList();//字段中文名称
private final ArrayList fieldEnName = new ArrayList();//字段英文名称
private final ArrayList fieldType = new ArrayList();//字段类型
private final ArrayList fieldSize = new ArrayList();//字段大小
private final ArrayList fieldDefaultValue = new ArrayList();//默认值
private final ArrayList isModify = new ArrayList();//可修改项
private final ArrayList isNeed = new ArrayList();//必须项
private final ArrayList isSelect = new ArrayList();//可查询项
private String dataOfChoice = null;//选择项数据
private HashMap dataOfChoiceMap = new HashMap();//保存选择项数据哈西表
private String documentChName = null;//文档中文名称
private String documentEnName = null;//文档英文名称
private int documentType;//文档类型,0:普通 1:填空
private String errors = null;
private String textContent = null;
public void reset(ActionMapping mapping,HttpServletRequest request)
{
dataOfChoice = null;
dataOfChoiceMap.clear();
documentChName = "";
documentEnName = "";
textContent = "";
errors = "";
documentType = 0;
fieldChName.clear();
fieldEnName.clear();
fieldType.clear();
fieldSize.clear();
fieldDefaultValue.clear();
isModify.clear();
isNeed.clear();
isSelect.clear();
} private void doSomethingWhenSet(ArrayList list,int key,Object value)//调用set方法时所做的处理
{
if(key >= list.size())
{
int arrayListSize = list.size();
for(int i = 0;i < key - arrayListSize;i ++)
{
list.add(arrayListSize + i,"");
}
list.add(key,value);
}
else
list.set(key,value);
} /*将dataOfChoice中的值拆分开放入HashMap中*/
private void setDataOfChoiceToMap(String dataOfChoice)
{
StringTokenizer stForColumn = new StringTokenizer(dataOfChoice,"|||");
while(stForColumn.hasMoreTokens())
{
StringTokenizer stForIDAndItem = new StringTokenizer(stForColumn.nextToken(),"&&&");
String columnID = stForIDAndItem.nextToken();
String columnItems = stForIDAndItem.nextToken();
StringTokenizer stForEveryItem = new StringTokenizer(columnItems,"***");
ArrayList itemList = new ArrayList();
while(stForEveryItem.hasMoreTokens())
itemList.add(itemList.size(),stForEveryItem.nextToken());
dataOfChoiceMap.put(columnID,itemList);
}
} private String tidyTextContent(String textContent)//将文本内容中的换行用\n替换
{
char [] charTextContent = textContent.toCharArray();
StringBuffer returnString = new StringBuffer();
for(int i = 0;i < charTextContent.length;i ++)
{
System.out.println((int)charTextContent[i]);
if((int)charTextContent[i] == 10 || (int)charTextContent[i] == 13)
returnString.append("\\n");
else
returnString.append(charTextContent[i]);
}
return returnString.toString();
}