📄 securityimpl.java
字号:
import java.net.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import hp.chaiserver.*;
public class SecurityImpl implements ISecurity, hp.chaiserver.IChaiServer
{
Environment env1;
public void initWorkerArgs(String name, IDaemon daemon, ArgVector args) {
}
Thread thread;
// securityRun is an implementation of the method defined in ISecurity
public void securityRun(String retFormat, ArgVector args, Environment env) {
// The next two lines obtain utility objects from the environment
// retStat is used to return status information
// html is used to stream HTML data back to client
HTMLStatus retStat = env.getErrResponder();
HTMLHelperBase html = (HTMLHelperBase) env.getHTMLHelper();
try {
// Replace the following three lines of code with your implementation
html.sendDataHeader("ChaiServer Object", null);
html.sendData("<P>securityRun called");
html.sendDataFooter();
} catch (Exception exe) {
Daemon.out.println("Exception thrown by HtmlHelper" + exe);
}
}
// homePage is an implementation of a method declared in hp.chaiserver.IChaiServer
public void homePage(OutputStream out, Environment env) {
// get HTMLHelperBase object from Environment. Used for streaming HTML
HTMLHelper html = (HTMLHelper) env.getHTMLHelper();
try {
//html.startHTMLDoc();
html.startHTMLMetaDoc("content=\"10\"");
// send <CENTER> Tag
html.startTag("CENTER");
// send Heading String
html.appendSimpleHTMLPara("Security Application", "H1");
// send </CENTER> Tag
html.endTag("CENTER");
// send <HR> Tag
html.startTag("HR");
try{
java.sql.Connection conn,conn1;
Statement st,st1;
ResultSet rs,rs1;
String ctime1,ptime1;
int ct1,ct2,ct3,ct4,pt1,pt2,pt3,pt4,dt1,dt2,dt3,dt4;
pt1=pt2=pt3=pt4=0;
ct1=ct2=ct3=ct4=0;
dt1=dt2=dt3=dt4=0;
////****** ******/////
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:test2000");
st = conn.createStatement();
rs = st.executeQuery("select * from security where slno = (select count(*) from security)");
while(rs.next())
{
ctime1 = rs.getString(2);
ct1 = rs.getInt(3);
ct2 = rs.getInt(4);
ct3 = rs.getInt(5);
ct4 = rs.getInt(6);
System.out.println("CTime "+ctime1+"CT1 "+ct1+"CT2 "+ct2+"CT3 "+ct3+"CT4 "+ct4);
html.appendSimpleHTMLPara("Current values:","H2");
html.appendSimpleHTMLPara("Time "+ctime1+" Temp1: "+ct1+" Temp2: "+ct2+" Temp3: "+ct3+" Temp4: "+ct4, "H3");
}
conn1 = DriverManager.getConnection("jdbc:odbc:test2000");
st1 = conn1.createStatement();
rs1 = st1.executeQuery("select * from security where slno = (select count(*)-1 from security)");
while(rs1.next())
{
ptime1 = rs1.getString(2);
pt1 = rs1.getInt(3);
pt2 = rs1.getInt(4);
pt3 = rs1.getInt(5);
pt4 = rs1.getInt(6);
System.out.println("PTime "+ptime1+"PT1 "+pt1+"PT2 "+pt2+"PT3 "+pt3+"PT4 "+pt4);
html.appendSimpleHTMLPara("Previous values:","H2");
html.appendSimpleHTMLPara("Time: "+ptime1+" Temp1: "+pt1+" Temp2: "+pt2+" Temp3: "+pt3+" Temp4: "+pt4, "H3");
}
dt1 = ct1 - pt1;
dt2 = ct2 - pt2;
dt3 = ct3 - pt3;
dt4 = ct4 - pt4;
if(dt1 < 0){
dt1 = -dt1;
}
if(dt2 < 0){
dt2 = -dt2;
}
if(dt3 < 0){
dt3 = -dt3;
}
if(dt4 < 0){
dt4 = -dt4;
}
if(dt1 > 5){
System.out.println("Fluctuation in Temperature1: "+dt1);
html.appendSimpleHTMLPara("Fluctuation in Temperature1: "+dt1, "H3");
}
if(dt2 > 5){
System.out.println("Fluctuation in Temperature2: "+dt2);
html.appendSimpleHTMLPara("Fluctuation in Temperature2: "+dt2, "H3");
}
if(dt3 > 5){
System.out.println("Fluctuation in Temperature3: "+dt3);
html.appendSimpleHTMLPara("Fluctuation in Temperature3: "+dt3, "H3");
}
if(dt4 > 5){
System.out.println("Fluctuation in Temperature4: "+dt4);
html.appendSimpleHTMLPara("Fluctuation in Temperature4: "+dt4, "H3");
}
rs.close();
rs1.close();
st.close();
st1.close();
conn.close();
conn1.close();
////****** *****/////
}catch(Exception e) { }
// send <P> Tag
html.startNewHTMLParagraph();
// send <HR> Tag
html.startTag("HR");
// send a sequence of Tags for a link to
// the home page of the local server
html.sendHomeLink(); // send end of document Tags
html.endHTMLDoc();
}catch (IOException io){}
}
// exportMethods is an implementation of a method declared in hp.chaiserver.IChaiServer
public void exportMethods(OutputStream out, String str, Environment env) {
// If you don't want to implement this Method, use the next three lines of code
// HTMLStatus retStat = env.getErrResponder();
// retStat.sendError(400,"The exportMethods Property is not supported");
// return;
// Otherwise at least return the name of all methods
HTMLHelperBase html = (HTMLHelperBase) env.getHTMLHelper();
// send HTML document header
try {
html.sendDataHeader("ChaiServer Object", null);
html.sendData("<P>ISecurity has the following methods:<P>");
html.sendData("<P>securityRun");
html.sendDataFooter();
} catch (Exception exe) {
Daemon.out.println("Exception thrown by HtmlHelperBase" + exe);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -