当然是可以的,通过RMI或你将服务器提供的服务封装成webservice,哪
就可跨操作系统。

解决方案 »

  1.   

    一楼的搞那么复杂干吗,通过servlet的url可以建立输入流和输出流,不就什么都解决了
      

  2.   

    import java.io.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.net.*;public class ReceiceServlet extends HttpServlet
    {
      SendDataThread sdt;
      public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
      {
        //res.setContentType("text/html");
        ServletOutputStream out =res.getOutputStream();
        String msg=req.getParameter("message");
        out.println("收到消息:"+msg);
        try
        {
          if(!msg.equals(""))
          {
            //String p=req.getParameter("port");
            int port;
            port=8080;
            String host;
            host="XXXXXX";
            Socket sock=new Socket(host,port);
            sdt=new SendDataThread(sock,msg);
            sdt.start();
          }
        }
        catch(Exception e)
        {
          out.println(e.toString());
        }
      }}
    class  SendDataThread extends  Thread
     {
        //成员变量
        protected  BufferedReader  inStream;
        protected  PrintWriter outStream;
        protected  Socket  socket;
        String msg;    //成员函数
        public  SendDataThread(Socket sock,String str)  //构造函数
        {
          try{
            this.socket=sock;
            inStream  =  new  BufferedReader(new  InputStreamReader(this.socket.getInputStream()));
            outStream  =  new  PrintWriter(this.socket.getOutputStream(),  true);
            meg=str;
          }catch(Exception ee)
          {      }    }    public   void  run()            //重载run方法
        {
          try
          {
             sendData(msg);
          }
          catch(Exception e)
          {
          }
          finally
          {
              outStream.close();
              this.socket.close();
           }
        }
        //////////////////    ////////////////////////
        /////////////////////////
        public  void  sendData(String  msg) throws  IOException  //发送数据
        {
          try
          {
            //outStream
            outStream.println(msg);
            outStream.flush();
            //outStream.close();
            //this.socket.close();
            //System.out.println(">>sendMsgFromBuffer3发送数据结束:");
          }
          catch(Exception  E)
          {
            //System.out.println(">>ERR sendData(...):"+E.toString());
          }
        }
     }