以下是我的jsp页面的代码:(action中接受数据没有问题,能取到页面中list中已经存在的数据,insRow()方法添加上去的数据取不到)
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'ruleList.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function getRowObj(obj)
{
var i = 0;
while(obj.tagName.toLowerCase() != "tr"){
obj = obj.parentNode;
if(obj.tagName.toLowerCase() == "table")
return null;
}
return obj;
}//删除一行数据
function del(obj){
var tr = this.getRowObj(obj);
if(tr != null){
tr.parentNode.removeChild(tr);
}else{
throw new Error("the given object is not contained by the table");
}
}
//新增一行数据
function insRow(){
var table = document.getElementById("table");
var tr = table.insertRow();
var td;
td = tr.insertCell();
td.innerHTML = "<input type='text' id='123456' name='formatList[tr.rowIndex-1].source' style='width: 100%;text-align: center' value='请输入'/>";
td = tr.insertCell();
td.innerHTML = "<input type='text' name='formatList[tr.rowIndex-1].url' style='width: 100%;text-align: center' value=''/>";
td = tr.insertCell();
td.innerHTML = "<input type='text' name='formatList[tr.rowIndex-1].urlFilter' style='width: 100%;text-align: center' value=''/>";
td = tr.insertCell();
td.innerHTML = "<input type='text' name='formatList[tr.rowIndex-1].newsType' style='width: 100%;text-align: center' value=''/>";
td = tr.insertCell();
td.innerHTML = "<input type='button' name='' value='删 除' onclick='javascript:del(this)'/>";
}</script>
</head>
<body>
<form action="xmlSaveAction!saveXMLInfo.do" method="post">
<div id="div1">
<table id="table" align="center" width="100%" border="1">
<tr>
<th align="center">资讯来源</th>
<th align="center">资讯来源链接</th>
<th align="center">资讯匹配链接</th>
<th align="center">资讯类别</th>
<th align="center">操 作</th>
</tr>
<s:iterator value="list" id="item" status="index">
<tr id="<s:property value='#index.index+1'/>" >
<td align="center" ><input type="text" name="formatList[<s:property value='#index.index'/>].source" style="width: 100%;text-align: center" value="<s:property value='#item.source' />"/></td>
<td align="center"><input type="text" name="formatList[<s:property value='#index.index'/>].url" style="width: 100%;text-align: center" value="<s:property value='#item.url' />"/></td>
<td align="center"><input type="text" name="formatList[<s:property value='#index.index'/>].urlFilter" style="width: 100%;text-align: center" value="<s:property value='#item.urlFilter' />"/></td>
<td align="center"><input type="text" name="formatList[<s:property value='#index.index'/>].newsType" style="width: 100%;text-align: center" value="<s:property value='#item.newsType' />"/></td>
<td align="center">
<input type="button" name="" value="删 除 "onclick="javascript:del(this)"/>
</td>
</tr>
</s:iterator>
</table>
</div>
<table width="99%">
<tr>
<td align="right">
<input type="button" name="" value="增 加 "onclick="javascript:insRow()"/>
<input type="submit" name="submit" value="保 存 "/>
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'ruleList.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function getRowObj(obj)
{
var i = 0;
while(obj.tagName.toLowerCase() != "tr"){
obj = obj.parentNode;
if(obj.tagName.toLowerCase() == "table")
return null;
}
return obj;
}//删除一行数据
function del(obj){
var tr = this.getRowObj(obj);
if(tr != null){
tr.parentNode.removeChild(tr);
}else{
throw new Error("the given object is not contained by the table");
}
}
//新增一行数据
function insRow(){
var table = document.getElementById("table");
var tr = table.insertRow();
var td;
td = tr.insertCell();
td.innerHTML = "<input type='text' id='123456' name='formatList[tr.rowIndex-1].source' style='width: 100%;text-align: center' value='请输入'/>";
td = tr.insertCell();
td.innerHTML = "<input type='text' name='formatList[tr.rowIndex-1].url' style='width: 100%;text-align: center' value=''/>";
td = tr.insertCell();
td.innerHTML = "<input type='text' name='formatList[tr.rowIndex-1].urlFilter' style='width: 100%;text-align: center' value=''/>";
td = tr.insertCell();
td.innerHTML = "<input type='text' name='formatList[tr.rowIndex-1].newsType' style='width: 100%;text-align: center' value=''/>";
td = tr.insertCell();
td.innerHTML = "<input type='button' name='' value='删 除' onclick='javascript:del(this)'/>";
}</script>
</head>
<body>
<form action="xmlSaveAction!saveXMLInfo.do" method="post">
<div id="div1">
<table id="table" align="center" width="100%" border="1">
<tr>
<th align="center">资讯来源</th>
<th align="center">资讯来源链接</th>
<th align="center">资讯匹配链接</th>
<th align="center">资讯类别</th>
<th align="center">操 作</th>
</tr>
<s:iterator value="list" id="item" status="index">
<tr id="<s:property value='#index.index+1'/>" >
<td align="center" ><input type="text" name="formatList[<s:property value='#index.index'/>].source" style="width: 100%;text-align: center" value="<s:property value='#item.source' />"/></td>
<td align="center"><input type="text" name="formatList[<s:property value='#index.index'/>].url" style="width: 100%;text-align: center" value="<s:property value='#item.url' />"/></td>
<td align="center"><input type="text" name="formatList[<s:property value='#index.index'/>].urlFilter" style="width: 100%;text-align: center" value="<s:property value='#item.urlFilter' />"/></td>
<td align="center"><input type="text" name="formatList[<s:property value='#index.index'/>].newsType" style="width: 100%;text-align: center" value="<s:property value='#item.newsType' />"/></td>
<td align="center">
<input type="button" name="" value="删 除 "onclick="javascript:del(this)"/>
</td>
</tr>
</s:iterator>
</table>
</div>
<table width="99%">
<tr>
<td align="right">
<input type="button" name="" value="增 加 "onclick="javascript:insRow()"/>
<input type="submit" name="submit" value="保 存 "/>
</td>
</tr>
</table>
</form>
</body>
</html>
解决方案 »
- pudn的会员,谁有pudn会员的账号,帮我下点东西,可以提供下这几个的下载地址吗?
- 怎么获取struts *.do的*?
- JAVA 连接SQLserver数据库报错
- 大家帮忙解决一个由struts配置文件引起的,导至Tomcat启动时间长的问题
- 请问EJB3.0和STRUTS2.0整合的问题,谢谢了
- 救命!●●● [xml转xsl问题!!] ●●●
- 在做下载功能时总是报一下的错误"20:49:23,453 ERROR [Engine] StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw ex
- 急!怎样实现jsp与php的通信?
- tomcat下,客户端ie6升级到sp1出现session过期的错误……
- springmvc是单例的,开发的时候会不会影响性能呢?
- Exception starting filter struts2如何解决
- java zip 的壓縮問題
加了getter和setter方法;只要这样能取到formatList的值的,
现在我的问题是insRow()方法添加上去数据通过formatList取不到值