- From: Mark I. Lubin <mil@phys.physics.ucf.edu>
- Date: Tue, 09 Jul 1996 13:00:49 -0500
- To: kendal@interlog.com
- Cc: www-jigsaw@w3.org
The following (this was wrriten by Anselm essentially) works and may help you: 1) compile and install on Jigsaw //ReverseString.java: package w3c.jigsaw.contrib; import java.util.*; import w3c.jigsaw.http.*; import w3c.jigsaw.forms.*; public class ReverseString extends PostableResource { public Reply handle(Request request, URLDecoder data) throws HTTPException { String str = data.getValue("string"); if ((str == null) || str.equals("")) { Reply reply = request.makeReply(HTTP.OK); reply.setContent("reverse=[]"); return reply; } // Reverse the string (should be some other method, etc) // You could ameliroate this alot, but that's not the point char cs[] = new char[str.length()]; str.getChars(0, cs.length, cs, 0); char cr[] = new char[cs.length]; for(int i = 0 ; i < cs.length; i++) cr[cs.length-1-i] = cs[i]; // Emit reply: Reply reply = request.makeReply(HTTP.OK); reply.setContent("reverse=["+new String(cr)+"]"); return reply; } public ReverseString() { } } on the client side: //ReverseTest.java import java.io.*; import java.net.*; public class ReverseTest { public static void main(String args[]) { try { if (args.length != 1) { System.err.println("Usage: java ReverseTest string_to_reverse"); System.exit(1); } String stringToReverse = URLEncoder.encode(args[0]); // Put you URL here !!! URL url = new URL("http://cmt.physics.ucf.edu:9999/User/reverse"); System.out.println("protocol = " + url.getProtocol()); System.out.println("host = " + url.getHost()); System.out.println("filename = " + url.getFile()); System.out.println("port = " + url.getPort()); System.out.println("ref = " + url.getRef()); URLConnection connection = url.openConnection(); // writing to URL PrintStream outStream = new PrintStream(connection.getOutputStream()); DataInputStream inStream; String inputLine; outStream.println("string=" + stringToReverse); outStream.close(); // reading from URL inStream = new DataInputStream(connection.getInputStream()); while (null != (inputLine = inStream.readLine())) { System.out.println(inputLine); } inStream.close(); } catch (MalformedURLException me) { System.err.println("MalformedURLException: " + me); } catch (IOException ioe) { System.err.println("IOException: " + ioe); } } } Mark Lubin
Received on Tuesday, 9 July 1996 13:56:13 UTC