一、Tomcat啓動方式-註冊成系統服務
依賴環境:已經安裝JDK、解壓版Tomcat安裝包;
步驟:
1、進入解壓版Tomcat安裝路徑的bin目錄下,shift+右鍵啓動,點擊‘在此處打開命令窗口’(保證使用管理員身份進入)進入cmd界面;
2、輸入 "service.bat install",回車,之後如果提示安裝成功,則證明已安裝系統服務;
3、啓動“任務管理器”進入“服務”頁面,找到tomcat服務,修改啓動方式即可。
二、github下載Esri官方代理
網址:https://github.com/Esri/resource-proxy,下載之後將文件夾 java 拷貝到tomcat的webapps目錄下,修改proxy.config文件,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<ProxyConfig allowedReferers="*"
logFile="proxy_log.log"
logLevel="INFO"
mustMatch="true">
<serverUrls>
<-- 要跨域的網址 -->
<serverUrl url="http://services.arcgisonline.com" matchAll="true"/>
<serverUrl url="http://help.arcgis.com/" matchAll="true"/>
<serverUrl url="http://resources.arcgis.com/" matchAll="true"/>
<serverUrl url="http://developers.arcgis.com/" matchAll="true"/>
<serverUrl url="http://enterprise.arcgis.com/" matchAll="true"/>
<serverUrl url="http://esri.github.io/" matchAll="true"/>
<serverUrl url="http://services.arcgisonline.com" matchAll="true"/>
</serverUrls>
</ProxyConfig>
三、測試
1、輸入:http://tomcat所在服務器IP:端口/Java/proxy.jsp?ping,出現以下:
{ "Proxy Version": "1.1.2", "Configuration File": "OK", "Log File": "OK"}
2、輸入:http:// tomcat所在服務器IP:端口/Java/proxy.jsp?http://arcgis server服務器IP:6080/arcgis/rest/services/?f=pjson
出現相應的服務信息,則證明成功。
四、最後在代碼中加入以下代碼即可:
esriConfig.request.proxyUrl = "http://tomcat所在服務器IP:端口/Java/proxy.jsp";