首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

does not contain handler parameter named 'opp'. This may be caused by whitespac

2012-01-19 
does not contain handler parameter named opp.This may be caused by whitespace in the label text我

does not contain handler parameter named 'opp'. This may be caused by whitespace in the label text
我在用Struts 做项目的时候 用到了 DispatchAction 这个类 但是当我提交的时候 就出现了这个问题:
does not contain handler parameter named 'opp'. This may be caused by whitespace in the label text

现在给出我写的源码:
希望有高手指点。。。=!

Jsp页面:<%@ page language="java" pageEncoding="UTF-8"%>

<html:html lang="true">
<head>
<html:base />

<title>addPerson.jsp</title>
<script type="text/javascript">
function doSubmit(op){
document.forms[0].elements["op"].value = op;
document.forms[0].submit();
}
</script>
</head>

<body>
<div style="text-align: center; width: 100%; height: 500px;"
align="center">
<div style="text-align: center; width: 700px; height: 500px;"
align="center">
<html:form action="/personInfo">
<html:hidden property="opp"/>
<p>
个人信息
</p>

<div style="text-align: center; size: 12px;">
<table width="100%" border="0" style="text-align: left;">
<tr>
<td width="80" height="15">
姓名:
</td>
......略。。。。。
<td>
<label>
<html:select property="rid">
<html:options collection="listRelation" property="rid"
labelProperty="rname" />
</html:select>
<html:errors property="rid" />
</label>
</td>
</tr>
<tr>
<td>
婚姻状况:
</td>
<td>
<html:select property="mid">
<html:option value="1">未婚</html:option>
<html:option value="2">已婚</html:option>
<html:option value="3">离异</html:option>
</html:select>
<html:errors property="mid" />
</td>
<td width="160" style="text-align: right;">
所属户:
</td>
<td>
<html:select property="hid">
<html:option value="1">一户</html:option>
<html:option value="2">二户</html:option>
<html:option value="3">三户</html:option>
</html:select>
<html:errors property="mid" />
</td>
</td>
</tr>
<tr>
<td>
定居原因:
</td>
<td>
<html:select property="moveStateId">
<html:options collection="listMove" property="moveStateId"
labelProperty="moveReason" />
</html:select>
<td width="160" style="text-align: right;">
服务处所:
</td>
<td>
<html:text property="unit" />
<html:errors property="unit" />
</td>
</tr>
<tr>
<td height="15">
居住地址:
</td>
<td colspan="3">
<html:text property="caddress" style="width:500px" />
<html:errors property="caddress" />
</td>


</tr>
<tr>
<td height="15" colspan="4">
<label>
<div align="center">
<html:submit value="提交" onclick="doSubmit('submit')" />
&nbsp;&nbsp;
<html:cancel value="取消"></html:cancel>
</div>
</label>
</td>
</tr>
<tr>
<td height="15">
&nbsp;
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
</table>
</div>
</html:form>

</div>

</div>
</body>
</html:html>
<script type="text/javascript">
document.all("psex")[0].checked = true;
</script>
Struts-config.xml:[color=#FF6600][/color]
 <action-mappings >
  <action
  attribute="personInfoForm"
  input="/business/personInfo.jsp"
  name="personInfoForm"
  path="/personInfo"
  parameter="opp"
  scope="request"
  type="com.yourcompany.struts.action.PersonInfoAction" >
  <forward name="add" path="/business/addPerson.jsp"></forward>
  </action>
配置文件其他省略了。。。
DispatchAction 类 :
public ActionForward submit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
PersonInfoForm personInfoForm = (PersonInfoForm) form;// TODO Auto-generated method stub
IPersonInfoDao personInfoDao = new PersonInfoDao();
int count = personInfoDao.addPesonInfo(personInfoForm);
if(count > 0){
System.out.println("sucess!");
return mapping.findForward("add");
}else{
return mapping.findForward("add");
}
}
FormBean:
private String opp;private String pname;
private String peverName;
private int bid;
private String cardId;
private int psex;
private String pdate;
private int nid;
private int cid;
private String nativePlace;
private String religion;
private String job;
private int rid;
private int mid;
private int hid;
private int moveStateId;
private String unit;
private String caddress;
由于发帖限制 重要的给出来了 其余的略了。。。

[解决办法]
既然
FormBean: 
private String opp; private String pname; 
private String peverName; 
private int bid; 
private String cardId; 
private int psex; 
private String pdate; 
private int nid; 
private int cid; 
private String nativePlace; 
private String religion; 
private String job; 
private int rid; 
private int mid; 
private int hid; 
private int moveStateId; 
private String unit; 
private String caddress; 
在formBean这样定义这些属性。生成对应set和get方法,页面上对应这些
那你
<html:hidden property="opp"/> 
.
.
.
<html:errors property="caddress" />
就应该这样写
 
<html:hidden property="formbean.opp"/> 
.
.
.
<html:errors property="formbean.caddress" /> 

------解决方案--------------------


1.FormBean: 
检查下private String opp;是否有set,get方法
2.
<action-mappings >
<action
attribute="personInfoForm"
input="/business/personInfo.jsp"
name="personInfoForm"
path="/personInfo"
parameter="opp" //建议改下名字,这里与FormBean的属性opp重复
scope="request"
type="com.yourcompany.struts.action.PersonInfoAction" >
<forward name="add" path="/business/addPerson.jsp"> </forward>
</action> 

热点排行