2014-05-12 192 views
-3

我正在尝试开发手机gap.It应用程序监视服务器作业。目前服务器不可用,所以我将我的系统作为服务器。我把项目文件放在我的服务器安装在同一个目录下。我正尝试在主要活动中访问我的文件。但它在我的模拟器上显示错误。错误标题是协议不支持。我在下面共享主要活动文件和html文件。请看这些文件。 主要活动文件:不支持协议(Android)

package com.example.productionmonitor; 
import org.apache.cordova.DroidGap; 
import android.os.Bundle; 
import android.view.Menu; 

public class MainActivity extends DroidGap{ 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     System.out.println("Here"); 
     super.setIntegerProperty("loadUrlTimeoutValue",120000); 
     super.loadUrl("file////C:/Program Files/Elixir Technologies/Tango/tomcat/webapps/productionmanagerserver/Monitor app/productionMonitor.htm"); 
     //super.loadUrl("file:///android_asset/www/productionMonitor.htm"); 
     //super.loadUrl("C:///|\Program Files\/Elixir Technologies\/Tango\tomcat\webapps\productionmanagerserver\Monitor app\productionMonitor.htm"); 
     //super.loadUrl("http:///localhost:8080/productionmanagerserver/productionMonitor.htm"); 

    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

} 

这是HTML文件我保存在位置(C:\ Program Files文件\药剂技术\探戈\ tomcat的\的webapps \ productionmanagerserver \监控应用\ login.html的)和我想访问这个文件。

<!doctype html> 
<html lang="en-US"> 
<head> 

    <meta charset="utf-8"> 

    <title>Login</title> 

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Varela+Round"> 
    <link rel="stylesheet" href="./files/login.css"> 

    <!--[if lt IE 9]> 
     <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
    <![endif]--> 

    <script> 
    var strFile ; 
    function userLogin() 
    { 
     window.location.href = "productionMonitor.htm"; 
    } 
    function init() 
     { 
      var xmlhttp = null ; 
      try { 
       xmlhttp = new XMLHttpRequest(); 
      } catch (trymicrosoft) { 
       try { 
        xmlhttp = new ActiveXObject("MsXML2.XMLHTTP"); 
       } catch (othermicrosoft) { 
        try { 
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
        } catch (failed) { 
          xmlhttp = null; 
         } 
        } 
       } 

      if (xmlhttp == null) 
      alert("Error creating request object!"); 

      if ("withCredentials" in xmlhttp) { 

       // Check if the XMLHttpRequest object has a "withCredentials" property. 
       // "withCredentials" only exists on XMLHTTPRequest2 objects. 
       //xhr.open(method, url, true); 

      } else if (typeof XDomainRequest != "undefined") { 

       // Otherwise, check if XDomainRequest. 
       // XDomainRequest only exists in IE, and is IE's way of making CORS requests. 
       xmlhttp = new XDomainRequest(); 

      }    

      return xmlhttp ; 
     } 

     function CallWebservice() 
     { 

      var req = init() ; 

      var url ="http://localhost:8080/identityserver/domains/allData"; 
      req.open('GET',url,true); 
      req.send(null);    
      req.onreadystatechange = function() { 
       if (req.readyState != 4) return; // Not there yet 
       if (req.status != 200) { 
        // Handle request failure here... 
        alert("Call failed"); 
        return; 
       } 
       // Request successful, read the response 
       strFile = req.responseText ; 
       parseDomainList(strFile);      
      } 
     } 

     function parseDomainList(dlist) 
     { 
      var xmlDoc = new DOMParser().parseFromString(strFile,'text/xml'); 
      var domain = xmlDoc.getElementsByTagName("domain"); 
      for (i=0;i<domain.length;i++) 
      { 
       var dname =domain[i].getElementsByTagName("domain_name"); 
       var domainid = document.getElementById("domain") ; 
       var option=document.createElement("option"); 
       domainid.appendChild(option);    
      } 
      alert(strFile) ; 
      userLogin() ; 
     } 

    </script> 

</head> 

<body> 

    <div id="login"> 

     <h2><span class="fontawesome-lock"></span>Sign In</h2> 

     <form action="javascript:void(0);" method="POST"> 

      <fieldset> 

       <p><label for="email">User Name</label></p> 
       <p><input type="email" id="email" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(admin')this.value=''"></p> 

       <p><label for="password">Password</label></p> 
       <p><input type="password" id="password" value="admin" onBlur="if(this.value=='')this.value='admin'" onFocus="if(this.value=='admin')this.value=''"></p> 

       <p><label for="domain">Domain List</label></p> 
       <p><select type="domain" id="domain"> </select> </p>     

       <p><input type="submit" value="Sign In" onclick="CallWebservice()"></p> 

      </fieldset> 

     </form> 

    </div> <!-- end login --> 

</body> 
</html> 

回答

1

把文件放在windows机器上的位置确实无关紧要。您的Android设备和模拟器都无法访问它们。如果你仔细想想,那会很吓人。

你需要把你的开发机器变成一个合适的服务器,然后用仿真器的特殊IP地址10.0.2.2访问它,这是开发机器的环回。如果您正在设备上进行测试,则需要访问开发计算机的本地IP地址,并假设您位于同一局域网内。