📄 customerimpl.java
字号:
import java.net.*;
import java.util.*;
import java.io.*;
import hp.chaiserver.*;
import java.sql.*;
public class CustomerImpl implements ICustomer, IChaiServer {
public void initWorkerArgs(String name, IDaemon daemon, ArgVector args) {
System.out.println("What is sysLogComand\t" + Utils.getSysLogCmd() + "\n");
}
// CustomerStore is an implementation of the method defined in ICustomer
public void CustomerStore(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();
HTMLHelper html = (HTMLHelper) env.getHTMLHelper();
// The following lines extract an argument from the ArgVector
// The CustomerString argument contains the String entered into the
// form.
String cname = args.getArg("cname");
String address = args.getArg("address");
String support = args.getArg("support");
if((cname == null) || (address == null) || (support == null)) {
retStat.sendError(400, "Insufficient Information");
return;
}
// Customer name trim to 25 characters.
if(cname.length() > 25){
cname = cname.substring(0,24);
}
// Customer address trim to 60 characters.
if(address.length() > 60){
address = address.substring(0,59);
}
// Customer Support details trim to 60 characters.
if(support.length() > 60){
support = support.substring(0,59);
}
// The following lines check the return format specified by
// client. This implementation supports HTML and Text.
// An error is sent to the client if return format is not supported
try {
if(retFormat.equalsIgnoreCase("html")) {
// startHTMLDoc sends the Header information to the client
html.startHTMLDoc();
// send a <HR> Tag
html.startTag("HR");
// send a <CENTER> Tag
html.startTag("CENTER");
// send contents of CustomerString formated as H1 in a paragraph
//html.appendSimpleHTMLPara(CustomerString, "H1");
// send a </CENTER> Tag
html.endTag("CENTER");
int count=0;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection conn = DriverManager.getConnection("jdbc:odbc:test2000");
Statement st = conn.createStatement();
ResultSet rs1= st.executeQuery("select count(*) from csd");
Calendar calendar = Calendar.getInstance();
String date = new String(calendar.get(Calendar.YEAR)+"-"+(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.DATE));
String time = new String(calendar.get(Calendar.HOUR)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND));
String datetime = new String(date+" "+ time);
if(rs1.next()) {
count = rs1.getInt(1) + 1;
} else {
count = 1;
}
rs1.close();
html.startTag("CENTER");
html.appendSimpleHTMLPara("Customer Support", "H2");
html.endTag("CENTER");
int rs = st.executeUpdate("insert into csd values("+count+",'"+datetime+"','"+cname+"','"+address+"','"+support+"')");
st.close();
conn.close();
}catch(Exception e) { e.printStackTrace(); }
html.startNewHTMLParagraph();
html.appendSimpleHTMLPara("Your complaint is Registered", "H2");
html.appendSimpleHTMLPara("and your ticket no is :"+count, "H2");
// send a <HR> Tag
html.startTag("HR");
// send a sequence of tags to create a link to
// this server's homepage
html.sendHomeLink();
// send the end of document tags
html.endHTMLDoc();
} else if(retFormat.equalsIgnoreCase("txt")) {
// send the MIME header for a text document and
// append the contents of CustomerString to the document
html.sendText(cname);
} else {
//retStat.send400("Return type " + retFormat + " not supported");
retStat.sendError(400, "Return type" + retFormat + "not supported");
}
}catch(IOException IO) { }
}
// homePage is an implementation of a method declared in hp.chaiserver.IChaiServer
public void homePage(OutputStream out, Environment env) {
// get HTMLHelper object from Environment. Used for streaming HTML
HTMLHelper html = (HTMLHelper) env.getHTMLHelper();
//System.out.println("What is sysLogComand\t" + Utils.getSysLogCmd() + "\n");
try {
// send HTML document header
html.startHTMLDoc();
// send <CENTER> Tag
html.startTag("CENTER");
// send Heading String
//html.appendSimpleHTMLPara("Customer Object", "H1");
html.appendSimpleHTMLPara("Customer ChaiService", "H1");
// send </CENTER> Tag
html.endTag("CENTER");
// send <HR> Tag
html.startTag("HR");
// send Tag sequence to start a form
html.startForm("GET", "/this.customer");
// send <P> Tag
html.startNewHTMLParagraph();
// add Hidden field called CustomerStore
// Note this represents the Method name to be
// called when the form is submitted. See the
// CustomerStore method above.
html.addHiddenField("CustomerStore", "html"); // Method and return type
// add a Text field called CSEID
// Note this represents the argument CSEID
// accessed in the CustomerStore method above.
html.appendSimpleHTMLPara("Customer Name: ", "H3");
html.addTextField("cname", 30, null);
html.startNewHTMLParagraph();
html.appendSimpleHTMLPara("Address: ", "H3");
html.addTextField("address", 60, null);
html.appendSimpleHTMLPara("Support Required/Problem:", "H3");
html.addTextField("support", 60, null);
// send <P> Tag
html.startNewHTMLParagraph();
// add a Submit button and reset button
html.addSubmitButton("Submit");
html.addResetButton();
// send the </FORM> tag
html.endForm();
// 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) { }
}
// Export is an implementation of a method declared in hp.chaiserver.IChaiServer
public void exportMethods(OutputStream out, String str, Environment env) {
// get HTMLHelper object from Environment. Used for streaming HTML
HTMLHelper html = (HTMLHelper) env.getHTMLHelper();
if(str.equalsIgnoreCase("html")) {
try {
// send HTML document header
html.startHTMLDoc();
// send <CENTER> Tag
html.startTag("CENTER");
// send Heading String
html.appendSimpleHTMLPara("Customer ChaiService", "H1");
// send </CENTER> Tag
html.endTag("CENTER");
// send <HR> Tag
html.startTag("HR");
html.appendSimpleHTMLPara("Method support: CustomerStore", "H3");
html.appendSimpleHTMLPara("Argument: CustomerString", "H3");
html.sendHomeLink(); // send end of document Tags
html.endHTMLDoc();
}catch(IOException io) {}
} else if(str.equalsIgnoreCase("txt")) {
try {
html.sendText("Method: CustomerStore\nArgument: CustomerString");
} catch(IOException io) { }
} else {
HTMLStatus retStat = env.getErrResponder();
retStat.sendError(400);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -