java - Send values from jsp to Servlet -


i have jsp in have select tag , want , value selected select in jsp in servlet

<select id="listoffood" name="dropdown" onchange="foodname();"> <option value="bg">burger</option> <option value="pas">pasta</option> <option value="pi">pizza</option> </select> <div id='content'></div> 

here javascript code

function foodname() {    var xmlhttpreq = false;     var self = this;     document.getelementbyid('content').innerhtml='';     // mozilla/safari     if (window.xmlhttprequest) {         self.xmlhttpreq = new xmlhttprequest();     }     // ie     else if (window.activexobject) {         self.xmlhttpreq = new activexobject("microsoft.xmlhttp");     }      self.xmlhttpreq.open('get', "informationservlet", true);     self.xmlhttpreq.setrequestheader('content-type', 'application/x-www-form-urlencoded');     self.xmlhttpreq.send(null);      self.xmlhttpreq.onreadystatechange= function ()     {         //alert(document.getelementbyid('content'));         if (self.xmlhttpreq.readystate==4)         {         if (self.xmlhttpreq.status == 200)         {          document.getelementbyid('content').innerhtml=self.xmlhttpreq.responsetext;         }         }     };  } 

what have done used attribute aint working showing null

protected void doget(httpservletrequest request, httpservletresponse response)                 throws servletexception, ioexception       {     // todo auto-generated method stub      string coun = request.getparameter("dropdown");     printwriter out=response.getwriter();     system.out.println("here : "+coun); } 

thanks in advance , piece of code highly appreciated.

just change ajax open() request as

var select = document.getelementbyid("listoffood"); self.xmlhttpreq.open('get', "informationservlet?dropdown=" + select.options[select.selectedindex].value, true); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -