如何使用jquery提交包含另一个jsp表单的JSP表单

时间:2015-05-08 07:16:32

标签: javascript jquery jsp struts2

嗨我在jquery(有保存和取消按钮)中有一个弹出对话框,它打开一个带有表单动作的jsp页面。在这个jsp中我包含了另一个带有保存按钮的jsp,这个jsp有动作。问题是:当我在没有包含第二个jsp的情况下保存第一个jsp时,它正在工作。但包括它后,它没有工作。以下是我的代码: 第一个弹出jsp:

function saveNewProcess() {

        var selIndex = $('#prolistframe').contents().find('#selectedIndex').val();
        /*if (selIndex === '') {
            alert('Select a process type');
            return;
        }
        */
        var pType = prolistframe.document.forms[0].proType.value;

        if (pType == 0 || pType == "") {
            alert("Select a process type to create new request.");
            return;
        }

        $('#selectedIndex').val(selIndex);

        if(flag==true){
            return;
        }
        flag=true;
        $('#processSaveDialog').dialog('destroy').remove();
        var url = 'indexfields_new.jsp?id='+pType+'&hide=true&random='+Math.random();
        $.get(url, function(data, textStatus) { 
          $("html, body").animate({ scrollTop: 0 }, "slow");
          $("<div id='processSaveDialog'/>").dialog({ 
              height: 700,
              width: 950,
              open:function(){
                  $(this).html(data);
                  flag=false;
              },
              buttons: {
                  "Save Process": function() {
                   saveProcess();
              },
              Cancel: function() {
                  $( this ).dialog( "close" );
              }
              },        
              modal: true,
              position:['middle',100],
              resizable: false,
              title: "Process Save Form"
           });
       });
    }


    function saveProcess(){

            saveData();
    }

    function saveData(){
        if(!checkMandatory()) return false;
        $('#indexFields').val(getIndexFields());
            if(!checkMandatory()) return false;

            $('#indexFields').val(getIndexFields());
            /* alert($('#processSaveForm').attr( 'action' )); */
            $('#action').val("saveNewProcess");
            $('#processSaveForm').attr('target','prolistframe');
            $('#processSaveForm').attr('action',$('#processSaveForm').attr( 'action' ));
            $('#processSaveForm').submit();
            $('#processSaveForm').attr('target','');
            alert("Processing Please Wait...");
            setTimeout(function(){
                alert("Process Saved Successfully");
                window.document.getElementById('prolistframe').src = window.document.getElementById('prolistframe').src;
               $('#processSaveDialog').dialog('destroy').remove();
            }, 4000);
}

第二个jsp:

<body> 
<form name="processSaveForm" id="processSaveForm" action="process" method="post" enctype="multipart/form-data">
<input type="hidden" name="action" id="action" value="saveNewProcess"/>

<table border="0" width="100%" style="float:left">
            <%
            int i=0,col=0;
            for(ProcessIndex d:proIndex){
                 String fields = "";
                 String id     = "";
                 int indexType = d.getDocumentIndexType().getId();
                 //System.out.println("index type::: "+indexType);
                 String required = "";
                 required=(d.getRequired()==1)?" mandatory":"";
                 if(indexType==DocumentIndexType.DATE){
                     fields="<input type=\'text\' name=\'idx" + i + "\' id=\'idx" + i + "\' alt=\'date:" + d.getId() + "\' class=\'date_field"+required+"\' readonly=\'readonly\'>"  ;
                 }
                 else if(indexType==DocumentIndexType.TEXT){
                     fields="<input type=\'text\' name=\'idx" + i + "\' id=\'idx" + i + "\' alt=\'" + d.getId() + "\' class=\'text_field"+required+"\' >"  ;
                 }else if(indexType==DocumentIndexType.DROP_DOWN){
                     fields="<select name=\'idx" + i + "\' id=\'idx" + i + "\' title=\'" + d.getId() + "\' class=\'drop_down"+required+"\'>";
                     fields += "<option value=\'\'>Select</option>";
                     List<ProcessIndexList> indList=processIndex.getProcessIndexList(d.getId());
                     for(ProcessIndexList ind:indList){
                         fields += "<option value=\'" + ind.getIndexValue() + "\'>" + ind.getIndexValue() + "</option>";
                     }
                     fields +="</select>";
                 }
 if(col==0){
                     out.write("<tr>");
                 }
                 col++;i++;
                 out.write("<td class=\"lbtext\">"+d.getName()+"</td><td " + id + "valign=\"middle\" >"+ fields +"</td>");
                 if(col==1){
                     out.write("</tr>");
                     col=0;
                 }
            }
           %>
           </table> 
<table align="center" width="100%" border="0">
        <tr><td>&nbsp;</td></tr>
        <tr>
            <td>
                <div align="center" id="forms" style="display:<%=hide%>;">
                <table align="center" border="0">
                    <tr>
                        <td align="center"><div  id="content1"> <jsp:include page="../admin/newActivity.jsp"/> </div></td>
                    </tr>
</table>
                </div>
            </td>
        </tr>
    </table>
        <input type="hidden" id="fieldCount" name="fieldCount" value="<%=i%>">
        <input type="hidden" id="rights" name="rights" value="<%=rights %>">
</form>
</body>

我的第三个包括第二个jsp中的jsp:

<body>
<form action="newActivity" name="newActivityForm" id="newActivityForm" method="post">   
<input type="hidden" id="action" name="action"/>
<p>New Activity</p>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #a3a4a9;" id="main_table">
        <tr>
            <td width="10%" height="20" align="left" bgcolor="#c7cbd6" class="table1">
                <input type="button" value="Save" onclick="saveNewActivity();"/>
            </td>
        </tr>
     </table>
    <table cellspacing="0" style="border: 1px solid black;" cellpadding="0" border="0" bgcolor="white" align="center" width="100%">
        <tr><td colspan="100%">&nbsp;</td></tr>
<tr>
            <td colspan="6"><textarea name="dca_comments" id="dca_comments" cols="50" rows="5"></textarea></td>
            <td colspan="6"><textarea name="dca_stamp" id="dca_stamp" cols="50" rows="5"></textarea></td>
        </tr>
        <tr><td colspan="100%">&nbsp;</td></tr>
    </table>
    <table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:1px solid #a3a4a9;" id="main_table">
        <tr>
            <td width="10%" height="20" align="right" bgcolor="#c7cbd6" class="table1">
                <input type="button" value="Save" onclick="saveNewActivity();"/>
            </td>
        </tr>
     </table>
    </form>
</body>

请帮我解决这个问题。完全被卡住了......感谢提前......

0 个答案:

没有答案