简单写了一个,只是验证一下数据流互相传送,具体功能可以自己加
test.java 客户端:读取1.xml文件发送给 DataServer(servlet),读取servlet返回的内容
DataServer.java 服务器servlet:读取test 发送的xml内容,把内容再返回给客户端
-----------------
|
-------------------------
/**
* Created by IntelliJ IDEA.
* User: dev
* Date: 2004-3-9
* Time: 12:44:41
* 服务器servlet,客户端数据,返回信息
*/
import javax . servlet. ServletException;
import javax . servlet. http. HttpServlet;
import javax . servlet. http. HttpServletRequest;
import javax . servlet. http. HttpServletResponse;
import java . io . ByteArrayOutputStream ;
import java . io . DataInputStream ;
import java . io . DataOutputStream ;
import java . io . IOException ;
public class DataServer extends HttpServlet {
public void service( HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*读取数据*/
DataInputStream in = new DataInputStream ( req. getInputStream ( ) ) ;
String stringValue = in . readUTF ( ) ;
/*返回数据*/
DataOutputStream dataOut = new DataOutputStream ( resp. getOutputStream ( ) ) ;
dataOut. writeUTF ( stringValue) ;
dataOut. flush ( ) ;
dataOut. close ( ) ;
}
}