Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 如何在struts 2中实现表单重新提交_Jsp_Struts2 - Fatal编程技术网

Jsp 如何在struts 2中实现表单重新提交

Jsp 如何在struts 2中实现表单重新提交,jsp,struts2,Jsp,Struts2,有谁能帮助我一步一步地实现令牌以避免Struts2中的重新提交问题 动作编码 public String enquiry_process() { qty=new ArrayList<BigDecimal>(); matcd=new ArrayList<Integer>(); purchaseRequisitionDets=procurementService.getPurchaseDet();

有谁能帮助我一步一步地实现令牌以避免Struts2中的重新提交问题

动作编码

public String enquiry_process()
{


    qty=new ArrayList<BigDecimal>();
    matcd=new ArrayList<Integer>();




            purchaseRequisitionDets=procurementService.getPurchaseDet();


            for(int i=0;i<orderCreationBean.getChk_no().length;i++)
            {

                Integer chkno=new Integer(i);
                chkno=orderCreationBean.getChk_no()[i];
                for(PurchaseRequisitionDet purchaseRDet:purchaseRequisitionDets)
                {
                    if(purchaseRDet.getPurch_req_no().equals(chkno))
                    {
                        PurchaseRequisitionDet  objPurchaseRequisitionDet =new PurchaseRequisitionDet();
                        objPurchaseRequisitionDet.setQty(purchaseRDet.getQty());
                        objPurchaseRequisitionDet.setMat_cd(purchaseRDet.getMat_cd());
                        objPurchaseRequisitionDet.setUnit(purchaseRDet.getUnit());
                        objPurchaseRequisitionDet.setUnit_price(purchaseRDet.getUnit_price());
                        objPurchaseRequisitionDet.setTotal(purchaseRDet.getTotal());
                        objprbeanarrays.add(objPurchaseRequisitionDet);
                    }
                }
            }

            HttpSession session=request.getSession(true);
            Integer id = (Integer) session.getAttribute("userId");

            procurementService.saveenqdet(enquiryBean.getRef_no(),objprbeanarrays,orderCreationBean,id);



            enquiryHeaderdets=procurementService.getenqhdr();
            for(EnquiryHeaderdet headerdet:enquiryHeaderdets)
            {
                if(headerdet.getRef_no().equals(enquiryBean.getRef_no()))
                {
                Long enq_no=headerdet.getEnq_no();
                qty=procurementService.createenq(enq_no);
                matcd=procurementService.getmatcd(enq_no);

                }
            }
            Long enqno=enquiryBean.getRef_no();

            for(int i=0;i<qty.size();i++)
            {   
                enquiryBean=new EnquiryBean();
                enquiryBean.setQty(qty.get(i).doubleValue());
                enquiryBean.setMat_cd(matcd.get(i));
                MaterialMaster mMaster=procurementService.getMaterial(matcd.get(i));
                enquiryBean.setMat_desc(mMaster.getMat_name());
                enquiryBeans.add(enquiryBean);

            }

            for(EnquiryHeaderdet headerdet:enquiryHeaderdets)
            {
                enquiryBean2=new EnquiryBean();
                if(headerdet.getRef_no().equals(enqno))
                {
                    enquiryBean2.setEnq_no(headerdet.getEnq_no());
                    break;
                }

            }

            orderCreationBean=new OrderCreationBean();
            enquiryBean=new EnquiryBean();
            objprbeanarrays=new ArrayList<PurchaseRequisitionDet>();


    return "success";

}
struts.xml

    <result name="success">/pages/procurement/EnquiryProcess.jsp</result>

    </action>   
当我刷新这个inquiryDetails.jsp它的perform before pageinquiryprocess.jsp时,我将提交一个值,然后再次重新提交并保存到数据库中。

步骤1:将该操作的无效令牌的结果放入struts.xml中

    <result name="success">/pages/procurement/EnquiryProcess.jsp</result>

    </action>   
仔细阅读此示例以理解。您还可以一步一步地找到许多教程


注意:您也可以使用注释来做同样的事情

感谢您宝贵的解决方案我在jsp中犯了一个错误,我把它放在其他元素之后,现在它可以工作了。我想您可以把它放在表单中的任何地方,但问题是你使用的语法…嗨,我还有一个疑问,如果我按back page back,它会再次保存。保存后,请尝试重定向到另一个页面,而不是forward。使用重定向。您还可以设置HTTP头值,如无缓存、pragma等,以便页面不会缓存在浏览器中。
 <result name="invalid.token">somePage.jsp</result>
<action name="tokenAction" class="yourPackageName.yourActionClass">
     <interceptor-ref name="token"></interceptor-ref>
        <!--
        OR <interceptor-ref name="tokenSession"></interceptor-ref>
         -->
     <interceptor-ref name="defaultStack"></interceptor-ref>
     <result name="success" >/success.jsp</result>
     <result name="invalid.token">/invalid_token.jsp</result>
</action>
<s:form action="tokenAction" method="post">
   <s:token />
   ....//other form elements
</s:form>
<html>
<body>
   Please do not resubmit. Resubmission is banned on this site.
</body>
</html>