1
서버 시작시 정기적으로 자바 스크립트 기능을 실행해야합니다. 내 JavaScript 함수를 여러 아약스 호출 및 수학 방정식을 포함하는 것과 동일한 Java 코드를 작성하는 방법을 모릅니다.ScheduledExecutorService를 사용하는 java 클래스 대신 Apache Tomcat 서버가 시작될 때 주기적으로 javascript 기능을 실행하는 방법은 무엇입니까?
아래는 서버 시작시 주기적으로 실행해야하는 자바 스크립트 코드입니다.
<script type="text/javascript">
$(document).ready(function(){
var polyLat = new Array();
polyLat[0] = 10.194027;
polyLat[1] = 10.226975;
polyLat[2] = 10.059987;
polyLat[3] = 10.002248;
polyLat[4] = 9.854925;
polyLat[5] = 9.835443;
polyLat[6] = 9.899107;
polyLat[7] = 9.993088;
polyLat[8] = 10.081425;
polyLat[9] = 9.992266;
polyLat[10] = 10.194027;//First point repeated to close polygon
var polySides = (polyLat.length)-1;//number of points in polygon
//vertical Longitude coordinates of polygon
var polyLng = new Array();
polyLng[0] = 76.201205;
polyLng[1] = 76.375022;
polyLng[2] = 76.775730;
polyLng[3] = 76.778940;
polyLng[4] = 76.584336;
polyLng[5] = 76.411473;
polyLng[6] = 76.368070;
polyLng[7] = 76.397007;
polyLng[8] = 76.317492;
polyLng[9] = 76.267905;
polyLng[10] = 76.201205;//First point repeated to close polygon
//Coordinates for bounding box
var maxLat = Math.max.apply(null,polyLat);
var minLat = Math.min.apply(null,polyLat);
var maxLng = Math.max.apply(null,polyLng);
var minLng = Math.min.apply(null,polyLng);
$.post('outboundupd.jsp',
{
mx_lat:maxLat,
mn_lat:minLat,
mx_lng:maxLng,
mn_lng:minLng,
ply_sds:polySides
},
function(response,status,xhr)
{
// alert(response.trim());
plotdata(response);
});
function plotdata(response)
{
var x;
var y;
var mob;
var jsonArray=JSON.parse(response.trim());
var jalen= jsonArray.length;
for(i=0;i<jalen;i++)
{
var obj=jsonArray[i];
pcode= obj.Pcode;
nplate= obj.N_plate;
driver= obj.Driver;
mob= obj.MobileNu;
x= obj.Latitude;
y= obj.Longitude;
time= obj.Time;
}
var j = polySides-1 ;
oddNodes = 0;
for (i=0; i<polySides; i++) {
if (polyLng[i]<y && polyLng[j]>=y || polyLng[j]<y && polyLng[i]>=y) {
if (polyLat[i]+(y-polyLng[i])/(polyLng[j]-polyLng[i])*(polyLat[j]-polyLat[i])<x) {
oddNodes=!oddNodes;
}
}
j=i; }
if(oddNodes!=true)
{
// alert("ob mobile:"+mob);
$.post('obsouth.jsp',
{
pcd:pcode,
npt:nplate,
drv:driver,
mobl:mob,
lat:x,
lon:y,
tm:time
},
function(response,status,xhr)
{
alert(response.trim());
});
}
return oddNodes;
}
});
</script>
내 질문 : -보다 Runnable로 확장 자바 클래스의 자바 스크립트 함수를 호출하거나 직접 자바 클래스의 정확한 자바 스크립트를 구현하기 위해 어떤 기술이
- 있습니까?
- 1에 대한 대답이 아니오라면 Java 코드로 전체 자바 스크립트를 변환하도록 안내해 주시겠습니까?
코드 일부는 매우 감사 드리며 미리 감사드립니다.
많은 그래픽 작업을하고있는 것처럼 보입니다. 이 그래픽이 서버에서 실행되고 있다면 어디에 나타나야합니까? – ControlAltDel
@ControlAltDel 예, 어디에도 나타나지 않아도됩니다. 방금 경계 조건 바깥에서 탐지 된 객체의 데이터베이스 레코드를 만듭니다. 마지막 if 조건 인 "if (oddNodes! = true)"가 경계 조건을 검사하고 조건이 만족되면 ajax 함수가 호출되어 해당 값을 데이터베이스에 씁니다. 나는이 전체 기능을 웹 페이지를 열지 않고 주기적으로 실행하여 하루에 한 번 확인해보고 이해할 수 있기를 바랍니다. – jasim
가장 좋은 방법은 node.js를 사용하고 Runtime.exec (...)을 사용하여 스크립트를 실행하는 것입니다. 여기에서 node를 실행하십시오. 참고 :이 경우 '문서'가 없기 때문에 가짜 스크립트를 만들거나 '문서'를 참조하는 행을 제거 할 수 있습니다. – ControlAltDel