android - Unable to receive response from the servlet -
i need retrieve control jsp response request fired earlier. problem facing not able response in jsp.
i have gone through few post , tried few suggestion none seems work me. please, point out mistake.
below try:
protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { log.info("in form doget"); request.setcharacterencoding("utf-8"); string selectedclass = request.getparameter("key"); log.info(selectedclass); string[] section = null; dbhandler dbhandler = new dbhandler(); dbhandler.makeconnection(); if (true == dbhandler.verifyconnection()) { section = dbhandler.getsection(selectedclass); } (string str : section) { log.info(str); } logger log; if (null != section) { request.setattribute(appconstants.section, section); } response.setheader("access-control-allow-origin", "*"); response.sendredirect("/reportfetcher/webcontent/firstjsp.jsp"); // requestdispatcher view = request.getrequestdispatcher("/first.jsp"); // view.forward(request, response); }
and below jsp part:
function funconchange() { var index = document.detail.class.selectedindex; var valueselected = document.detail.class.options[index].value; var xhr = new xmlhttprequest(); xhr.onreadystatechange = function() { // check see if state change "request complete", , // there no server error (404 not found, 500 server error, etc) if (xmlhttp.readystate==4 && xmlhttp.status==200) { var substring=xmlhttp.responsetext; alert("alert dialog! gaurav"); } if (xmlhttp.readystate == 404){ alert("404 error"); } if (xmlhttp.readystate == 500){ alert("500 error"); } } xhr.open('get', 'http://localhost:8080/reportfetcher/formhandler?key='+encodeuricomponent(valueselected), true); xhr.send(null); return false; }
i think doing right , suggested above should need forward request instead of redirecting request.
point going wrong making object of xmlhttprequest , referencing using variable xhr
while making request, when taking care of response @ time checking status of variable xmlhttp
, need replace variable xmlhttp
xhr
.
if face problem, feel free ask.
Comments
Post a Comment