我用了 struts+spring+hibernate 由JSP中的FORM提交到ACTION方法中执行 然后跳回JSP页面显示
问题是 同一个方法 被执行了两次
比如:我的JSP页面提交到ACTION中的 create方法 这个方法是得到JSP页面传过来的对象 然后插入数据库
结果是:插入了两次 也就是 数据库添加了2条数据
而删除的话 就是同一条数据删除了两次 所以在第二次删除的是够报 对象 为空的异常
有没谁能解决或者知道这从错误一般是由什么引起的
问题是 同一个方法 被执行了两次
比如:我的JSP页面提交到ACTION中的 create方法 这个方法是得到JSP页面传过来的对象 然后插入数据库
结果是:插入了两次 也就是 数据库添加了2条数据
而删除的话 就是同一条数据删除了两次 所以在第二次删除的是够报 对象 为空的异常
有没谁能解决或者知道这从错误一般是由什么引起的
<html:form action="sal_Plan.do" method="post">
<html:submit property="del" styleClass="common_button" onclick="forward('delPlaTodo&id='+${chancelist.chcId}+'&pid='+${lis.plaId});">删除 </html:submit>
</html:form>
<script language="JavaScript">
function forward(address){
document.forms[0].action="/CRMSystem/sal_Plan.do?method="+address;
document.forms[0].submit();
}
</script>
form:public class Sal_PlanForm extends BaseForm { private SalChance salChance = new SalChance();
private SalPlan salPlan = new SalPlan();
private SalPlan sal_create_Plan = new SalPlan();
public void setSalChance(SalChance salChance){
this.salChance = salChance;
}
public SalChance getSalChance(){
return salChance;
}
public void setSla_create_Plan(SalPlan sal_create_Plan){
this.sal_create_Plan = sal_create_Plan;
}
public SalPlan getSal_create_Plan(){
return sal_create_Plan;
}
public void setSalPlan(SalPlan salPlan){
this.salPlan = salPlan;
}
public SalPlan getSalPlan(){
return salPlan;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return null;
} /**
* Method reset
* @param mapping
* @param request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
// TODO Auto-generated method stub
}
}
action 方法
// //删除计划项
public ActionForward delPlaTodo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Sal_PlanForm sal_PlanForm = (Sal_PlanForm) form;// TODO Auto-generated
// method stub Sale_PlanBizImpl sale_planbiz = (Sale_PlanBizImpl) this
.getSale_planbiz(); long pid = Integer.parseInt(request.getParameter("pid")); sale_planbiz.delete(pid); return this.forwardPlan(mapping, form, request, response);
}
我用了 struts+spring+hibernate 由JSP中的FORM提交到ACTION方法中执行 然后跳回JSP页面显示
问题是 同一个方法 被执行了两次
比如:我的JSP页面提交到ACTION中的 create方法 这个方法是得到JSP页面传过来的对象 然后插入数据库
结果是:插入了两次 也就是 数据库添加了2条数据
而删除的话 就是同一条数据删除了两次 所以在第二次删除的是够报 对象 为空的异常
有没谁能解决或者知道这从错误一般是由什么引起的
document.forms[0].submit(); ......................................<html:form action="sal_Plan.do" method="post"> 你上面调了2次啊,也就是说请求了2次.
你把<html:form action="sal_Plan.do" method="post">
写成<html:form action="" method="post">
就ok了.................
改成<html:form action="" method="post">
报错说是 Cannot retrieve mapping for action /
然后改成
<html:form action="sal_Plan" method="post">
但是结果还是和<html:form action="sal_Plan.do" method="post">
没有区别
试试不要用submit,用一个普通的按钮
或者不要function forward了,直接提交