简体   繁体   中英

loading servlet from jsp and trying to pass multiple parameters

im trying to load a servlet using java script from a jsp. i am also trying to pass two parameter. the page loads but now im printing a sytem out from the servlet it suppose to give me the id and the vehicle vaules but it gives the vehicle felid as null.

ScanServlet doGet was called id = 1 vehicle= [object HTMLParagraphElement]vehicle=null

this is the code

  <body onload="notifyOnLoad(<%=request.getParameter("imgid")%>)">
    <img id="imgBarcode" src="ImageServlet?imgid=<%=request.getParameter("imgid")%>&vehicle=<%=request.getParameter("vehicle")%>" width=<%=request.getAttribute("Width")%> height=<%=request.getAttribute("Height")%>><br/>
    <h4>Barcode Details</h4>
    <p>Name :- <%=request.getAttribute("name")%></p>
    <p>Type :- <%=request.getAttribute("type")%></p>
    <p>Value :- <%=request.getAttribute("value")%></p>
    <p id="wtf">type :- <%=request.getParameter("vehicle")%></p>
    <script type="text/javascript">
        function notifyOnLoad(imgid) {
            var xmlhttp;
            var vehicle =document.getElementById("wtf");
            if(window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari;
                xmlhttp = new XMLHttpRequest();
            }
            else{
                /*code for IE6, IE5*/
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }

            xmlhttp.onreadystatechange = function() {
                if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    window.location = xmlhttp.responseText;
                }
            }
            xmlhttp.open("GET", "ScanServlet?imgid="+imgid+"vehicle="+vehicle, true);
            xmlhttp.send();
        }
    </script

>
 </body>

You cant directly access the request parameters in the javascript in the way you are trying.

<input type='hidden' name='field1' id='imgid' value='<%=request.getParameter("imgid")%>' />

access the variable in the javascript with its id,

<script type="text/javascript">
        function notifyOnLoad(imgid,vehicle) {
            var xmlhttp;
            var imgid=document.getElementById("imgid");
            xmlhttp.open("GET", "ScanServlet?imgid="+mgid+"&vehicle="+vehId, true);
            xmlhttp.send();
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM