how to get http response from Java Servlet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neovantage
    New Member
    • Aug 2008
    • 245

    how to get http response from Java Servlet

    Hi geeks,
    We made a Java Servlet which takes 3 parameters and upload files from source path to remote path. The three parameters are password, source path and destination path.

    When we run this command
    http://localhost:8080/FTPSClientServ/uploader?passwo rd=xxxxxx&local =D:\xampp\htdoc s\ews\nyc\data\ &remote=/Vanguard/fromVanguard/msd/
    on http browser it works perfectly fine and gives http response.

    Now i want to run this commmand in php document. I tried to execute that command in php document by making an ajax call it returns status 200 but along with it it gives an exception and does not give the http response.
    The exception is
    uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILU RE) [nsIXMLHttpReque st.send]" nsresult: "0x80004005 (NS_ERROR_FAILU RE)" location: "JS frame :: http://localhost/ews/nyc/test.php :: getGridlist :: line 43" data: no]
    Here is my code
    Code:
    <?php
    	define("DESTINATION_PATH","/Vanguard/fromVanguard/msd/");
    	$spassword = "xxxxxxx";
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    		<title>NYC</title>
            <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
            
            <script type="text/javascript">
    		
    			var objXMLHttp;
    			function GetXmlHttpObject(){
    				objXMLHttp=null;
    				try{
    					// Firefox, Opera 8.0+, Safari
    					objXMLHttp=new XMLHttpRequest();
    				}
    				catch (e){
    					// Internet Explorer
    					try{
    						objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP");
    					}
    					catch (e){
    						try{
    							objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    						}
    						catch (e){
    							jAlert('Please upgrade your browser','No AJAX Support');
    							return false;
    						}
    					}
    				}
    				return objXMLHttp;
    			}
    		
    		var src_path="D:\\xampp\\htdocs\\ews\\nyc\\data\\";
    		var xmlGridList=null;
    		function getGridlist(){
    			xmlGridList=GetXmlHttpObject();
    			url="http://localhost:8080/FTPSClientServ/uploader?password=<?=$spassword;?>&local="+src_path+"&remote=<?=DESTINATION_PATH;?>";
    		
    			xmlGridList.open('GET', url, false);
    			xmlGridList.onreadystatechange = $makeGrid;
    			xmlGridList.send();
    		}
    		function $makeGrid(){
    			if(xmlGridList.readyState==4){
    				if(xmlGridList.status==200){
    					alert(xmlGridList.responseText);
    				}else{
    					alert('An error occoured on the server the details are below <br />'+xmlGridList.status+'  '+xmlGridList.statusText);
    				}
    			}
    		}
            </script>
    	</head>
    	<body onload="javascript:getGridlist();"></body>
    </html>
    How can i get the http response in this technique. if this is not a validate way then what is the other way to do that?
    Awaiting of your response.
    Thanks in Advance,
    Mohsin Rafique
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if you include jQuery, why not using its AJAX functions?

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      it is giving exception at the point httt.send(null) if used get method with asynchronos=fal se or true it is not getting the responsetext although the status shows 200 against the call in firebug
      this was the case with jquery too
      do you think that servlet also need to be configured properly to return the http response headers

      note that it is uploading the file but not getting back the response , the guy who sent programmed the servlet told us that you need to have synchronus communication with the servlet where as AJAX is asynchronus ,
      but we are experiencing it for the first time ,
      and that Java guy is not avaiabe at the moment , although i think thats a blunder what he said that ajax could not communicate with the servlet i have seen alots of examples in the last 1 hour of searching that people are using jquery to call the servlet and return the response from the servlet
      what you think ....it would be alot more beter if a running example could be located only a simple one that could show how to do it .....i also read somewhere that we need to set the WWW-Authenticate headers in the AJAX call too but all these things are confusing until a simple running example could be seen and understood
      regards,
      Omer Aslam

      Comment

      Working...