各位大虾,帮帮忙了,这个问题困惑了好久了,下面我列出源码来,希望大家帮我看看原因.如果分太少的话我还可以给.多谢了!!
(方法一:静态文本框,设置了两个文本框)JSP页面:(
<table id='dynTable' width="100%" border="0" align="center" cellpadding="6" cellspacing="3" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse: collapse">
<tr>
<td><html:text property="items" value=""/></td>
<td><html:text property="version" value=""/></td>
<td><html:text property="re" value=""/></td>
<td><html:text property="explanation" value=""/></td>
</tr>
<tr>
<td><html:text property="items" value=""/></td>
<td><html:text property="version" value=""/></td>
<td><html:text property="re" value=""/></td>
<td><html:text property="explanation" value=""/></td>
</tr>
</table>相应的ActionForm代码为:
public class FtpEditForm extends ValidatorForm{
private String[] items;
private String[] version;
private String[] re;
private String[] explanation;
public String[] getExplanation() {
return explanation;
} /**
* @param explanation The explanation to set.
*/
public void setExplanation(String[] explanation) {
this.explanation = explanation;
} /**
* @return Returns the item.
*/
public String[] getItems() {
return items;
} /**
* @param item The item to set.
*/
public void setItems(String[] items) {
this.items = items;
} /**
* @return Returns the re.
*/
public String[] getRe() {
return re;
} /**
* @param re The re to set.
*/
public void setRe(String[] re) {
this.re = re;
} /**
* @return Returns the version.
*/
public String[] getVersion() {
return version;
} /**
* @param version The version to set.
*/
public void setVersion(String[] version) {
this.version = version;
}
}Action中的代码:
String[] items=ftpEditForm.getItems();
String[] versions=ftpEditForm.getVersion();
String[] res=ftpEditForm.getRe();
String[] explanations=ftpEditForm.getExplanation();
System.out.println(items[0]);
System.out.println(items[1]);
这是通过formben取出四个数组来,如果是静态文本框,通过测试能够取出值来,item[0],item[1]有值显示.方法二:动态文本框
JSP页面:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="struts.jsp"%>
<link href="../css/manage.css" rel="stylesheet" type="text/css"><html:html locale="true">
<head>
<title>FTP表单管理</title>
<link rel=stylesheet href="<html:rewrite page="../css/manage.css"/>" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/public/public.css" />
<link rel="stylesheet" type="text/css" href="../css/projectEdit.css" />
<link rel="stylesheet" type="text/css" href="../css/toolbar/toolbar1.css" /><Script Language=JavaScript>function insertRow(isTable){
index = isTable.rows.length;
nextRow = isTable.insertRow(index); //isText = nextRow.insertCell(0);
choice = nextRow.insertCell(0)
items = nextRow.insertCell(1); version = nextRow.insertCell(2); re = nextRow.insertCell(3);
explanation = nextRow.insertCell(4);
//choice = nextRow.insertCell(5);
index++;
index = index.toString();
itemStr = "item"+"["+index+"]";
versionStr = "version"+"["+index+"]";
reStr = "re"+"["+index+"]";
explanationStr = "explanation"+"["+index+"]";
choiceStr="choice"+index;
txtStr = index;
// isText.innerHTML = txtStr;
choice.innerHTML='<input type="radio" name="choiceStr">';
items.innerHTML = "<input type=text name="+itemStr+" size=20>";
version.innerHTML = "<input type=text name="+versionStr+" size=10>";
re.innerHTML = "<input type=text name="+reStr+" size=50>";
explanation.innerHTML = "<input type=text name="+explanationStr+" size=60>";
document.ftpEditForm.total.value=index;
}
function deleteRow(isTable){var c = document.getElementsByName('choiceStr');
for(var i=0; i<c.length; i++)
if(c[i].checked)
if(confirm("是否确定删除?")){
isTable.deleteRow(i);
document.ftpEditForm.total.value=document.ftpEditForm.total.value-1;
}}
</Script> <html:form action="/ftpFormFlow">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="A4B6D7" >
<tbody>
<tr>
<td>
<div class="toolbars" >
<span class="toolbar">
<ul>
<li id="torNew"> <html:submit property="action"><bean:message key="button.save"/></html:submit ></li>
</ul>
</span>
</div>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="A4B6D7" >
<tr>
<td height="25" colspan="2" align="center" background="../images/manage/xp_mid.gif"><font color="#FF0000">表单详细内容</font></td>
</tr>
<tr>
<td>
<div class="toolbars" >
<span class="toolbar">
<ul>
<li id="seperateline"></li>
<li id="torDel"><a href="javascript://" onclick="deleteRow(dynTable);">删除</a></a></li>
<li id="torNew"><a href="javascript://" onclick="insertRow(dynTable);">添加</a></li>
</ul>
</span>
</div>
</td>
</tr>
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse: collapse">
<tr align="center">
<td width="3%" rowspan="1"></td>
<td width="14%"rowspan="1"><strong>零件名</strong></td>
<td width="9%" rowspan="1"><strong>版本号</strong></td>
<td width="32%" rowspan="1"><strong>备注</strong></td>
<td width="42%" rowspan="1"><strong>说明</strong></td>
</tr>
</table>
<table id='dynTable' width="100%" border="0" align="center" cellpadding="6" cellspacing="3" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse: collapse"> </table>
</table>
</html:form>
</body>
</html:html>
actionform和action的代码跟静态的情况相同.在动态的这种方法里,我按"添加"按钮后会增加一个文本框,然后填入内容,actionform bean应该接收数组,但是保存时出现这个错误java.lang.NullPointerException
org.apache.commons.beanutils.PropertyUtils.setIndexedProperty(PropertyUtils.java:1458)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1013)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:169)看来是并没有从formbean中取出数组,所以才会出现java.lang.NullPointerException的.不知道是我的javascript写的有问题还是其他什么问题,我真是无计可施,恳请各位帮忙,在线等待.谢谢.
(方法一:静态文本框,设置了两个文本框)JSP页面:(
<table id='dynTable' width="100%" border="0" align="center" cellpadding="6" cellspacing="3" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse: collapse">
<tr>
<td><html:text property="items" value=""/></td>
<td><html:text property="version" value=""/></td>
<td><html:text property="re" value=""/></td>
<td><html:text property="explanation" value=""/></td>
</tr>
<tr>
<td><html:text property="items" value=""/></td>
<td><html:text property="version" value=""/></td>
<td><html:text property="re" value=""/></td>
<td><html:text property="explanation" value=""/></td>
</tr>
</table>相应的ActionForm代码为:
public class FtpEditForm extends ValidatorForm{
private String[] items;
private String[] version;
private String[] re;
private String[] explanation;
public String[] getExplanation() {
return explanation;
} /**
* @param explanation The explanation to set.
*/
public void setExplanation(String[] explanation) {
this.explanation = explanation;
} /**
* @return Returns the item.
*/
public String[] getItems() {
return items;
} /**
* @param item The item to set.
*/
public void setItems(String[] items) {
this.items = items;
} /**
* @return Returns the re.
*/
public String[] getRe() {
return re;
} /**
* @param re The re to set.
*/
public void setRe(String[] re) {
this.re = re;
} /**
* @return Returns the version.
*/
public String[] getVersion() {
return version;
} /**
* @param version The version to set.
*/
public void setVersion(String[] version) {
this.version = version;
}
}Action中的代码:
String[] items=ftpEditForm.getItems();
String[] versions=ftpEditForm.getVersion();
String[] res=ftpEditForm.getRe();
String[] explanations=ftpEditForm.getExplanation();
System.out.println(items[0]);
System.out.println(items[1]);
这是通过formben取出四个数组来,如果是静态文本框,通过测试能够取出值来,item[0],item[1]有值显示.方法二:动态文本框
JSP页面:
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="struts.jsp"%>
<link href="../css/manage.css" rel="stylesheet" type="text/css"><html:html locale="true">
<head>
<title>FTP表单管理</title>
<link rel=stylesheet href="<html:rewrite page="../css/manage.css"/>" type="text/css">
<link rel="stylesheet" type="text/css" href="../css/public/public.css" />
<link rel="stylesheet" type="text/css" href="../css/projectEdit.css" />
<link rel="stylesheet" type="text/css" href="../css/toolbar/toolbar1.css" /><Script Language=JavaScript>function insertRow(isTable){
index = isTable.rows.length;
nextRow = isTable.insertRow(index); //isText = nextRow.insertCell(0);
choice = nextRow.insertCell(0)
items = nextRow.insertCell(1); version = nextRow.insertCell(2); re = nextRow.insertCell(3);
explanation = nextRow.insertCell(4);
//choice = nextRow.insertCell(5);
index++;
index = index.toString();
itemStr = "item"+"["+index+"]";
versionStr = "version"+"["+index+"]";
reStr = "re"+"["+index+"]";
explanationStr = "explanation"+"["+index+"]";
choiceStr="choice"+index;
txtStr = index;
// isText.innerHTML = txtStr;
choice.innerHTML='<input type="radio" name="choiceStr">';
items.innerHTML = "<input type=text name="+itemStr+" size=20>";
version.innerHTML = "<input type=text name="+versionStr+" size=10>";
re.innerHTML = "<input type=text name="+reStr+" size=50>";
explanation.innerHTML = "<input type=text name="+explanationStr+" size=60>";
document.ftpEditForm.total.value=index;
}
function deleteRow(isTable){var c = document.getElementsByName('choiceStr');
for(var i=0; i<c.length; i++)
if(c[i].checked)
if(confirm("是否确定删除?")){
isTable.deleteRow(i);
document.ftpEditForm.total.value=document.ftpEditForm.total.value-1;
}}
</Script> <html:form action="/ftpFormFlow">
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="A4B6D7" >
<tbody>
<tr>
<td>
<div class="toolbars" >
<span class="toolbar">
<ul>
<li id="torNew"> <html:submit property="action"><bean:message key="button.save"/></html:submit ></li>
</ul>
</span>
</div>
</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="A4B6D7" >
<tr>
<td height="25" colspan="2" align="center" background="../images/manage/xp_mid.gif"><font color="#FF0000">表单详细内容</font></td>
</tr>
<tr>
<td>
<div class="toolbars" >
<span class="toolbar">
<ul>
<li id="seperateline"></li>
<li id="torDel"><a href="javascript://" onclick="deleteRow(dynTable);">删除</a></a></li>
<li id="torNew"><a href="javascript://" onclick="insertRow(dynTable);">添加</a></li>
</ul>
</span>
</div>
</td>
</tr>
<table width="100%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse: collapse">
<tr align="center">
<td width="3%" rowspan="1"></td>
<td width="14%"rowspan="1"><strong>零件名</strong></td>
<td width="9%" rowspan="1"><strong>版本号</strong></td>
<td width="32%" rowspan="1"><strong>备注</strong></td>
<td width="42%" rowspan="1"><strong>说明</strong></td>
</tr>
</table>
<table id='dynTable' width="100%" border="0" align="center" cellpadding="6" cellspacing="3" bordercolor="#CCCCCC" bgcolor="#FFFFFF" style="border-collapse: collapse"> </table>
</table>
</html:form>
</body>
</html:html>
actionform和action的代码跟静态的情况相同.在动态的这种方法里,我按"添加"按钮后会增加一个文本框,然后填入内容,actionform bean应该接收数组,但是保存时出现这个错误java.lang.NullPointerException
org.apache.commons.beanutils.PropertyUtils.setIndexedProperty(PropertyUtils.java:1458)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:1013)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:169)看来是并没有从formbean中取出数组,所以才会出现java.lang.NullPointerException的.不知道是我的javascript写的有问题还是其他什么问题,我真是无计可施,恳请各位帮忙,在线等待.谢谢.
解决方案 »
- 购物车问题,仙人请进
- win2003 数据查询的问题,在线等,急!!!
- struts2 action跳转问题
- 在tomcat下无法下载rar文件,而是直接打开了,求救!
- 问一个关于页面初始化的问题??
- 个人网站建立
- 怎么把javax的servlet包加到jdk可以访问的范围内??
- (●●●●,高分)在用jsp和mysql数据库中做的B/S构架中,如何在客户端读条形码?(急!在线等待)
- 请教各位大侠,怎样在用java语言判断在磁盘中的一个目录下是否有文件,并且把所有的文件名都提取出来,赋值到一个字符串数组中?
- 用jdbc连接sql2000出错
- 高手们,帮帮我吧,实在是做不出了。
- 菜鸟请教个技术问题,大侠请进~谢谢
items.innerHTML = "<input type=text name='items' size=20>";
version.innerHTML = "<input type=text name='version' size=10>";
re.innerHTML = "<input type=text name='re' size=50>";
explanation.innerHTML = "<input type=text name='explanation' size=60>";