如何将隐藏字段中的数据从一个jsp页传递到Java脚本页再传递到第三个jsp页?使用AJAX有可能吗?

时间:2019-06-24 07:15:05

标签: jsp

我有如下所示的代码 editProfile.jsp

    <form name="editP" id="editP"  method ="post">
        <input type="hidden" id="hiddenField" name="hiddenField" value="hiddenValue">
<td ><input type="text"  name="addressNew" id="addressNew" value="addressVal" class="reporttitle1"></input>
    < input type="button" value="Submit" id="Submit" onClick ="validateA('/registration/editConfirm.jsp?module=A')">

java脚本页面:

function validateA(url1){
var targetURL = url1+&address='+addressVal;
 var spanImageBox;
  var  xmlHttpObj1 = createRequestObject();
   if (xmlHttpObj1==null){
      alert ("Your browser does not support AJAX!");
      return;
    } 

    if (FirstValue=="Y"){   
        spanImageBox = document.getElementById('displaySpan1');
     }else{
       spanImageBox = document.getElementById('displaySpan');
     }

    xmlHttpObj1.onreadystatechange=function(){

      if(xmlHttpObj1.readyState == 4 || xmlHttpObj1.readyState == "complete") 
      {   
         if (xmlHttpObj1.status == 200 ) 
          {
            var outputResponse = trim(xmlHttpObj1.responseText);
            spanImageBox.innerHTML=xmlHttpObj1.responseText;

          } else { 
             spanImageBox.innerHTML = "<img src ='/images/loading.gif' border='0'>"; 
     } 

      }  

   }
   xmlHttpObj1.open("GET",url1,true);
   xmlHttpObj1.send(null);
}

所需的jsp页面:editConfirm.jsp 在这里,我尝试打印隐藏输入字段的值,但是“ request.getParameter(“ hiddenField”);“返回null。  当我在URL中传递参数然后它起作用时,代码就像onClick =“ validateA('/ registration / editConfirm.jsp?module = A&hiddenField = hiddenField')一样,但是我不想在URL中传递此参数。 / p>

<%@ page language="java" contentType="text/html" %>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.0//EN">
<HTML>
<body bgcolor="#ffffff" leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<%
    String  address = request.getParameter("addressNew");
    String  hiddenStr = request.getParameter("hiddenField");
    System.out.println(" hiddenStr  value: "+hiddenStr );
    //the hiddenStr is null
%>
</body>
</html>

0 个答案:

没有答案