如题... 
我想在Servlet中获取手机(客户端发过来的数据),下面的代码是我做的普通的java类,已经实现了接受手机端数据并保存道本地的功能, 
现在我想把这个移植到Servlet上面,请教大虾该怎么做?? 
急急急.. 
import java.net.*; 
import java.io.*; 
public class Server { 
public static void main(String[] args) throws Exception { 
ServerSocket ss = new ServerSocket(6666); 
int b=0; 
while(true) { 
Socket s = ss.accept(); 
InputStream is = s.getInputStream(); 
OutputStream out = new FileOutputStream("e:/2.txt"); 
while((b=is.read())!=-1){ 
      out.write(b); 

is.close(); 
out.close(); 
s.close(); 


}

解决方案 »

  1.   


    我该在哪个Servlet中使用request.getInputStream呢?
    下面是手机端程序
    public void sent(String[] text){
    StringBuffer sb = new StringBuffer();
    for(int i=0;i<text.length;i++){
           String str = text[i];
           sb.append(str);
          }
    Socket socket = new Socket("127.0.0.1/index.jsp", 8080,500);
    if (socket.isOpen())
    {
    String url = sb.toString();
    byte[] outBuf = url.getBytes();
    System.out.println("-------------------"+socket.readLine());
    // fetch page
    if (socket.writeBytes(outBuf, 0, outBuf.length) == outBuf.length)
    socket.close();
    }
    Socket.disconnect(); // not necessary, just illustrative
    }