<input>的name是动态获取的时候可以通过构成JSON传值给Action
jsp代码:
<script type="text/javascript" src="js/json2.js"></script>
<srcipt>
function p_edit(id) {
var name={
id:document.getElementById("id"+id).value,
area:document.getElementById("area"+id).value,
};
name=JSON.stringify(name);
targetForm = document.forms[0];
targetForm.action = "edit.action?param="+encodeURIComponent(name);
}
</script>
<s:iterator value="resultList1" status="stat" var="f">
<td><input type="text"
name="<s:property value='key' /><s:property value="#stat.count" />"
value="<s:property value="resultList1[#stat.index][key]" />" /></td>
</s:iterator>
<td><input type="image" src="./images/edit.png"
οnclick="p_edit(<s:property value="#stat.count" />);" /></td>
java代码
import net.sf.json.JSONObject;
HttpServletRequest request = ServletActionContext.getRequest();
JSONObject json;
json = JSONObject.fromObject(request.getParameter("param"));
//转码,解决request.getparameter 乱码
setPlot_area(new String(json.get("area").toString().getBytes("ISO8859-1"),"UTF-8"));
setPlot_id(new String(json.get("id").toString().getBytes("ISO8859-1"),"UTF-8"));