⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fibonaccisaxclient.java

📁 随书的代码
💻 JAVA
字号:
import java.net.*;import java.io.*;import java.math.BigInteger;import org.xml.sax.*;import org.xml.sax.helpers.*;public class FibonacciSAXClient {  public final static String DEFAULT_SERVER    = "http://www.elharo.com/fibonacci/XML-RPC";      public static void main(String[] args) {          if (args.length <= 0) {      System.out.println(       "Usage: java FibonacciSAXClient number url"      );      return;    }        String server = DEFAULT_SERVER;    if (args.length >= 2) server = args[1];          try {      // Connect to the server      URL u = new URL(server);      URLConnection uc = u.openConnection();      HttpURLConnection connection = (HttpURLConnection) uc;      connection.setDoOutput(true);      connection.setDoInput(true);       connection.setRequestMethod("POST");      OutputStream out = connection.getOutputStream();      Writer wout = new OutputStreamWriter(out);            // Transmit the request XML document      wout.write("<?xml version=\"1.0\"?>\r\n");        wout.write("<methodCall>\r\n");       wout.write(       "  <methodName>calculateFibonacci</methodName>\r\n");      wout.write("  <params>\r\n");       wout.write("    <param>\r\n");       wout.write("      <value><int>" + args[0]        + "</int></value>\r\n");       wout.write("    </param>\r\n");       wout.write("  </params>\r\n");       wout.write("</methodCall>\r\n");             wout.flush();      wout.close();            // Read the response XML document      XMLReader parser = XMLReaderFactory.createXMLReader(        "org.apache.xerces.parsers.SAXParser"      );      // There's a name conflict with java.net.ContentHandler      // so we have to use the fully package qualified name.      org.xml.sax.ContentHandler handler        = new FibonacciHandler();      parser.setContentHandler(handler);          InputStream in = connection.getInputStream();      InputSource source = new InputSource(in);      parser.parse(source);      System.out.println();      in.close();      connection.disconnect();    }    catch (Exception e) {      System.err.println(e);     }    } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -