java - servlets: get the null parameters by ajax in servlets -


string isno1=request.getparameter("isbn");         string bktitle2=request.getparameter("booktitle");         string authr3=(string) request.getparameter("author");         system.out.println(isno1+bktitle2+authr3);         enumeration paramaternames = request.getparameternames();   

when taking parameters in servlet gettin values 'null'

what wrong doing.

this way setting parameters...

from jsp page using script tag

 <script type="text/javascript">             function gethttpobject()             {                 var httpobject;                 if(!httpobject && typeof(xmlhttprequest) != 'undefined')                     {                     try{                         httpobject=new xmlhttprequest();                     }                     catch(e){                         xmlhttp=false;                     }                     }                 return httpobject;              }               var httpob=gethttpobject();               function handlehttpresponse(){                 if(httpob.readystate==4){                     //alert("sd");                     var result=httpob.responsetext;                     alert(result);                     /* document.write("hi book submitted !!!!!"); */                 }             }             function auth(){                 var params="isbn="+document.mayurform.isbn.value+"&booktitle="+document.mayurform.booktitle.value+"&author="+document.mayurform.author.value;                 alert("params sending"+params);                 httpob.open("post","addbook",true);                  httpob.setrequestheader("content-type","application/x-www-form-urlencoded");                 httpob.setrequestheader("content-length",params.length);                 httpob.setrequestheader("connection","close");                 /* httpob.setrequestheader("content-type","application/x-www-from-urlencoded");                 httpob.setrequestheader("content-length",params.length);                 httpob.setrequestheader("connection","close"); */                 httpob.onreadystatechange=handlehttpresponse;                 httpob.send();             }           </script> 

and form.....

<form style="margin: 100px;"   name="mayurform">     <table align="center">         <tr>         <td align="center">isbn no.</td>         <td><input align="middle" type="text" size="20" name="id" id="isbn">         </tr>         <tr>         <td align="center">book-title</td>         <td><input align="middle" type="text" size="20" name="pwd" id="booktitle">         </td>         </tr>         <tr>         <td align="center">author</td>         <td><input align="middle" type="text" size="20" name="pwd" id="author">         </tr>         <tr>         <td><input align="middle" type="button" size="20" name="add-book" onclick="auth()">         </tr>     </table>  </form> 

use below ajax send() send data

function auth(){                 var params="isbn="+document.mayurform.isbn.value+"&booktitle="+document.mayurform.booktitle.value+"&author="+document.mayurform.author.value;                 alert("params sending"+params);                 .......                 ...                 httpob.send(params);//change here              } 

call httpob.send(),passing in parameters sent (without "?" prefix).


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -