Skip to content

Instantly share code, notes, and snippets.

@sameek
Created May 25, 2012 09:01
Show Gist options
  • Save sameek/2786811 to your computer and use it in GitHub Desktop.
Save sameek/2786811 to your computer and use it in GitHub Desktop.
Ajax File
function setbrowser()
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (typeof XMLHttpRequest == "undefined")
XMLHttpRequest = function () {
try {
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
}
catch (e) {}
try {
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
}
catch (e) {}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {}
//Microsoft.XMLHTTP points to Msxml2.XMLHTTP.3.0 and is redundant
throw new Error("This browser does not support XMLHttpRequest.");
};
}
function replaceButtonText(command,servicemanagerid)
{
if(command=='pause')
{
alert(servicemanagerid)
alert(command)
sendQuery(command,servicemanagerid);
}
else if(command=='resume')
{
alert(servicemanagerid)
alert(command)
sendQuery(command,servicemanagerid);
}
else if(command=='stop')
{
alert(servicemanagerid)
alert(command)
sendQuery(command,servicemanagerid);
}
else if(command=='start')
{
alert("Not Implemented yet..")
}
else if(command=='shutdown')
{
alert(servicemanagerid)
alert(command)
sendQuery(command,servicemanagerid);
}
}
function sendQuery(command,servicemanagerid)
{
setbrowser();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// document.getElementById("grid").innerHTML=xmlhttp.responseText;
}
}
//alert("search?query="+query+"&limit="+qlimit+"searchtxt="+searchtxt+"&list="+list);
xmlhttp.open("POST","Action.jsp?command="+command+"&servicemanagerid="+servicemanagerid+"",true);
alert(command+" request send sucessfully,please wait..")
xmlhttp.send();
}
function startTimer()
{
alert("starttimer");
getView();
aTimer = window.setInterval("getView()",5000);
// return false;
}
function getView()
{
setbrowser();
xmlhttp.onreadystatechange=function()
{
alert("onreadystatechange")
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("monitordiv").innerHTML=xmlhttp.responseText;
addRowColor()
}
}
xmlhttp.open("POST","View.jsp",true);
xmlhttp.send();
}
function getViewForStartService()
{
setbrowser();
xmlhttp.onreadystatechange=function()
{
//alert("onreadystatechange")
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// alert(xmlhttp.responseText);
document.getElementById("pageviewdiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","start_services.jsp",true);
xmlhttp.send();
}
function getViewForServiceStatus()
{
setbrowser();
xmlhttp.onreadystatechange=function()
{
alert("onreadystatechange")
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
document.getElementById("pageviewdiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","service_status.jsp",true);
xmlhttp.send();
}
function addRowColor()
{
var table = document.getElementById("tableview");
var rows = table.getElementsByTagName("tr");
document.getElementById("tableview").style.border="thick solid #0000FF"
for(i = 0; i < rows.length; i++)
{
if(i==0)
{
rows[i].style.backgroundColor= "";
rows[i].className = "tableheader";
}
else if(i % 2 == 0)
{
rows[i].style.backgroundColor= "";
rows[i].className = "odd";
}
else
{
rows[i].style.backgroundColor= "";
rows[i].className = "even";
}
}
}
<html>
<head> <Title> Service Monitor</Title>
<script type="text/javascript" src="resources/js/Ajax.js"></script>
</head>
<body>
<%@include file="/page_header.jsp" %>
<div id="pageviewdiv">
</div>
</body>
</html>
<%--
Document : page_header
Created on : May 23, 2012, 5:56:50 PM
Author : SAMEEK
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body align="left">
<div id="header" align="left">
<img src="logo.JPG" />
</div><br/>
&nbsp;&nbsp;<a href="#" onclick="getViewForStartService()"> <b>Start Services</b></a> || <a href="service_status.jsp"><b>Service Status</b></a> || <a href="#"><b>Home</b></a>
<br/><br/>
</body>
</html>
<%--
Document : service_status
Created on : May 23, 2012, 5:55:34 PM
Author : SAMEEK
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head> <Title> Service Monitor</Title>
<script type="text/javascript" src="resources/js/Ajax.js"></script>
</head>
<body onload="startTimer()">
<br/>
<div id="monitordiv"> </div>
</body>
</html>
<%--
Document : start_services
Created on : May 23, 2012, 6:02:22 PM
Author : SAMEEK
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Start Service</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
<%@page import="java.util.List"%>
<%@page import="com.arosys.hibernatedatamanager.ServiceManagerDetailsDAO"%>
<%@page import="org.apache.log4j.Logger"%>
<%@page import="com.arosys.logger.LoggerFactory"%>
<%@page import="com.arosys.hibernatedatamanager.ServiceManagerDetails"%>
<%@page import="java.util.Iterator"%>
<%@page import="org.hibernate.Query"%>
<%@page import="org.hibernate.Session"%>
<%@page import="org.hibernate.SessionFactory"%>
<%@page import="org.hibernate.cfg.Configuration"%>
<%@page import="java.net.URL"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<html>
<head> <Title> Service Monitor </Title>
<script type="text/javascript" src="resources/js/Ajax.js"></script>
<link type="text/css" rel="stylesheet" href="resources/css/tablesheet.css">
</head>
<body>
<%@include file="/page_header.jsp" %>
<form onload="addRowColor()">
<table border="1" align="center" id="tableview" >
<tr>
<td>S.No</td>
<td>Service ManagerID</td>
<td>Service Mode</td>
<td>Service Type</td>
<td>status</td>
<td>control Queue</td>
<td>control ExchangeName</td>
<td>control Routingkey</td>
<td colspan="3" align="center">Action</td>
</tr>
<%String Status = null;
String servicemode = null;%>
<%
try {
ServiceManagerDetailsDAO managerDao = new ServiceManagerDetailsDAO();
//ServiceManagerDetails managerdetails = new ServiceManagerDetails ();
List list = managerDao.findAllWithNotClause();
for (Iterator it = list.iterator(); it.hasNext();) {
ServiceManagerDetails std = (ServiceManagerDetails) it.next();
%>
<tr>
<td><%=std.getservicedetailsID()%> </td>
<td><%=std.getservicemanagerID()%> </td>
<td><%=std.getservicemode()%></td>
<td><%=std.getservicetype()%></td>
<td><%=std.getservicemanagerstatus()%></td>
<td><%=std.getcontrolQueue()%></td>
<td><%=std.getcontolExchange()%></td>
<td><%=std.getcontrolRoutingkey()%></td>
<%
Status = std.getservicemanagerstatus();
servicemode = std.getservicemode();
if (Status.equals("Running")) {
%>
<td><input name="pause"id="pause" type="Button" value="Pause" onclick="replaceButtonText('pause','<%=std.getservicemanagerID()%>') "/></td>
<td><input id="shutdown" type="Button" value="Shutdown" onclick="replaceButtonText('shutdown','<%=std.getservicemanagerID()%>')" /></td>
<%
} else if (Status.equals("Pause")) {
%>
<td><input name="resume"id="resume" type="Button" value="Resume" onclick="replaceButtonText('resume','<%=std.getservicemanagerID()%>') "/></td>
<td><input id="shutdown" type="Button" value="Shutdown" onclick="replaceButtonText('shutdown','<%=std.getservicemanagerID()%>')" /></td>
<%
}
if (servicemode.equals("ONDEMAND") && Status.equals("Running") || Status.equals("Pause")) {%>
<td><input id="stop" type="Button" value="Stop" onclick="replaceButtonText('stop','<%=std.getservicemanagerID()%>')" /></td>
<%} else if (servicemode.equals("ONDEMAND") && Status.equals("Idle")) {%>
<td><input id="start" type="Button" value="Start" onclick="replaceButtonText('start','<%=std.getservicemanagerID()%>')" /></td>
<% }
%>
</tr>
<%
}
%>
<%
} catch (Exception e) {
e.printStackTrace();
}
%>
</table>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment