A number of communication methods for several servlets

xiaoxiao2021-03-06  84

1. GET MLL URL = New URL (servlet IP, Port and Parameter ..) DataInputStream Reader = New DataInputStream (Url.OpenStream ()) 2. POST General Mode URL URL URL = New URL (Servlet IP, Port) URL Connetion Conn = URL .openConnection (); ... postData = parameter name = parameter value & parameter name = parameter value setting content_type ... ByteArrayoutputstream baos = new byterrayoutputstream (512) baos.writeto (Conn.getputStream ()) Parameters Send a separate mode of the above Servlet Request.getParameter ("Parameter Name")

3. Object Serialized Post Method URL URL = New URL (Servlet IP, Port) URL Connection CONN = Url.openConnection ();

ByteArrayOutputStream byteOut = new ByteArrayOutputStream () ObjectOutputStream out = new ObjectOutputStream (byteOut) out.writeObject (value1) out.writeObject (value2) ... byte buf [] = byteOut.toByteArray (); provided Content-type Content-length DataOutputStream dataOut = new DataOutputStream (conn.getOutputStream ()) dataOut.write (buf); .... the method Servlet receives ObjectInputStream in = new ObjectInputStream (request.getInputStream ()) to give value1 = in.readObject (0 obtained value2 = in. ReadObject (0 Do you think the best above? Please express your opinion!

转载请注明原文地址:https://www.9cbs.com/read-108073.html

New Post(0)