见如下文档:
http://www.itfuture.org/show.jsp?cid=146
一定要给分呀!
以后有问题可以到
  http://www.itfuture.org/liuy
  上提问有问必答!!

解决方案 »

  1.   

    很久以前写玩的,没仔细看,有问题在问我。/**
     * This client send 1 byte 1000 times.
     */
    import java.io.*;
    import java.net.*;/**
     * @author Chen Jay
     */
    public class TCPClient { public static void main(String[] args) {
    // TODO Auto-generated method stub
    Socket client;
    int count = 0;
    long start;
    long end;
    try {
    if (args.length != 2) {
    System.out.println("Usage: java TCPClient <host> [port]");
    return;
    }
    start = System.currentTimeMillis();
    while (count < 1000) {
    client = new Socket(args[0], Integer.parseInt(args[1]));
    DataOutputStream out = new DataOutputStream(client
    .getOutputStream());
    client.getInputStream();
    out.write("a".getBytes());
    client.close();
    count++;
    }
    end = System.currentTimeMillis();
    System.out.println("One loops cost:"
    + (double) ((end - start) / 1000) + "ms");
    } catch (UnknownHostException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }}
      

  2.   

    使用jndi,给个例子,使用ejb,只写一个SessionBeanimport javax.naming.*;
    import javax.ejb.*;
    import java.net.*;
    import java.io.*;public class HTMLReaderBean implements SessionBean {
     
      public StringBuffer getContents() throws HTTPResponseException {     Context context;
         URL url;
         StringBuffer buffer;
         String line;
         int responseCode;
         HttpURLConnection connection;
         InputStream input;
         BufferedReader dataInput;
     
         try {
            context = new InitialContext();
            url = (URL)context.lookup("java:comp/env/url/MyURL");  
            connection = (HttpURLConnection)url.openConnection();
            responseCode = connection.getResponseCode();
         } catch (Exception ex) {
             throw new EJBException(ex.getMessage());
         }     if (responseCode != HttpURLConnection.HTTP_OK) {
            throw new HTTPResponseException("HTTP response code: " + 
               String.valueOf(responseCode));
         }     try {
            buffer = new StringBuffer();
            input = connection.getInputStream();
            dataInput = new BufferedReader(new InputStreamReader(input));
            while ((line = dataInput.readLine()) != null) {
               buffer.append(line);
               buffer.append('\n');
            }  
         } catch (Exception ex) {
             throw new EJBException(ex.getMessage());
         }     return buffer;  } // getContents()   public HTMLReaderBean() {}
       public void ejbCreate() {}
       public void ejbRemove() {}
       public void ejbActivate() {}
       public void ejbPassivate() {}
       public void setSessionContext(SessionContext sc) {}} 
      

  3.   

    用URLConnection 最方便,参考以下代码:
    URL url = new URL("http://www.abc.com/abc.html");
    URLConnection conn = url.openConnection();
    InputStream inStream = conn.getInputStream();FileOutputStream fs = new FileOutputStream(outputFilename);
    byte[] buffer = new byte[1024];
    int length=0;
    int byteread = 0;
    int bytesum = 0;
    while ((byteread = inStream.read(buffer)) != -1) {
        bytesum += byteread;
        fs.write(buffer, 0, byteread);
    }
    fs.close();
      

  4.   

    strHtml是网页的Html代码 URLConnection uc = new URL(url).openConnection();
    uc.setConnectTimeout(10000);
    uc.setDoOutput(true);

    InputStream in = new BufferedInputStream(uc.getInputStream());
    Reader rd = new InputStreamReader(in);
    int c = 0;
    StringBuffer temp = new StringBuffer();
    while ((c = rd.read()) != -1) {
    temp.append((char) c);
    }
    in.close();

    strHtml = temp.toString(); //strHtml请求网页代码
      

  5.   

    通过ajax获取之后,然后通过隐藏文本通过form表单最后提交给java类哦
    如下: <script type="text/javascript">var xmlHttp;function createXMLHttpRequest() {    if (window.ActiveXObject) {        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");    }    else if (window.XMLHttpRequest) {        xmlHttp = new XMLHttpRequest();    }}function startRequest() {
         var name= document.bianji.name.value;
        createXMLHttpRequest(); 
        xmlHttp.open("GET", "./newmessage.html", true);
        xmlHttp.setRequestHeader("Content-Type","GBK");
        xmlHttp.onreadystatechange = handleStateChange;
        xmlHttp.send(null);
        xmlhttp.setRequestHeader("If-Modified-Since","0");   
    }
    function handleStateChange() {    if(xmlHttp.readyState == 4) {
        
              
            if(xmlHttp.status == 200) {      
               document.bianji.message.value = xmlHttp.responseText;
            }    }}</script>
    <form action="类名" name="bianji" method="POST"> 
     
        <table width=800>
      <tr> 
      <td> <input type="hidden"  name="message" value=""/>
                     <input type="submit"  value="提交 "   onclick="startRequest();"/>
      </td>
      </tr>        
        </table>        
     </form>