Results 1 to 5 of 5
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,025
    Rep Power
    8

    Default reverse server server reversed etc.

    I am studying two subjects at the same time: patterns and networking.
    The next small app is taken from the Java tutorials about URL.
    I do fully understand the technical working of the program (which is not the issue here)!
    The Program, a smaller server, reads two command line arguments:
    1) the address of the server;
    2) a string argument, which will be reserved;

    The question is what is really going on:
    -when I start the program from the compiler, with whom it is talking?
    -so I should upload the app as a jar file at my host?
    -There are now two applications, right, one at the compiler and one at my host
    -I start the first one at my compiler and feed it the http of the host with /Reverse.jar.....
    -Than what happens and who is talking to who (knock, knock)?

    What is going on here I do not get it!



    Java Code:
    import java.io.*;
    import java.net.*;
    
    public class Reverse {
        public static void main(String[] args) throws Exception {
    
            if (args.length != 2) {
                System.err.println("Usage:  java Reverse "
                    + "http://<location of your servlet/script>"
                    + " string_to_reverse");
                System.exit(1);
            }
    
            String stringToReverse = URLEncoder.encode(args[1], "UTF-8");
    
            URL url = new URL(args[0]);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
    
            OutputStreamWriter out = new OutputStreamWriter(
                                             connection.getOutputStream());
            out.write("string=" + stringToReverse);
            out.close();
    
            BufferedReader in = new BufferedReader(
                                        new InputStreamReader(
                                        connection.getInputStream()));
            String decodedString;
            while ((decodedString = in.readLine()) != null) {
                System.out.println(decodedString);
            }
            in.close();
        }
    }
    Last edited by willemjav; 07-14-2013 at 12:49 PM.

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,025
    Rep Power
    8

    Default Re: reverse server server reversed etc.

    Ok when I give the two command lines what server address I should provide?
    Should the application be at that server address?
    Or should I do it at a local address?
    The tutorial lists this address: Example Domain
    When putting that address and the next argument "hello", happens this:
    (but where can I find my "olleh"?

    XML Code:
    <!doctype html>
    <html>
    <head>
        <title>Example Domain</title>
    
        <meta charset="utf-8" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <style type="text/css">
        body {
            background-color: #f0f0f2;
            margin: 0;
            padding: 0;
            font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
            
        }
        div {
            width: 600px;
            margin: 5em auto;
            padding: 50px;
            background-color: #fff;
            border-radius: 1em;
        }
        a:link, a:visited {
            color: #38488f;
            text-decoration: none;
        }
        @media (max-width: 700px) {
            body {
                background-color: #fff;
            }
            div {
                width: auto;
                margin: 0 auto;
                border-radius: 0;
                padding: 1em;
            }
        }
        </style>    
    </head>
    
    <body>
    <div>
        <h1>Example Domain</h1>
        <p>This domain is established to be used for illustrative examples in documents. You may use this
        domain in examples without prior coordination or asking for permission.</p>
        <p><a href="http://www.iana.org/domains/example">More information...</a></p>
    </div>
    </body>
    </html>
    BUILD SUCCESSFUL (total time: 2 seconds)

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,025
    Rep Power
    8

    Default Re: reverse server server reversed etc.

    The principle question is: what is really a server?
    (Netbeans does not take the two arg under project properties etc.)
    Last edited by willemjav; 07-15-2013 at 11:43 AM.

  4. #4
    serotonin is offline Member
    Join Date
    Jan 2013
    Location
    england
    Posts
    9
    Rep Power
    0

    Default Re: reverse server server reversed etc.

    i am learning that part of the URL tutorial aswell..
    seems like the example weblink will not be very useful to us,
    as the only way to get your text reversed is to use the ReverseServlet,

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default Re: reverse server server reversed etc.

    Example.com is (as the site says) there simply to act as a dummy placeholder for a website address.
    It's not intended as the actual address you use in the app.
    You need to have a server that has the ReverseServlet running on it.
    Tomcat is the usual candidate.
    Please do not ask for code as refusal often offends.

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2012, 10:26 PM
  2. Replies: 6
    Last Post: 12-25-2011, 11:33 PM
  3. smtp server configuration with jboss server
    By vilas_patil in forum Java Servlet
    Replies: 0
    Last Post: 01-05-2009, 01:18 PM
  4. Does any file in an FTP server ends up in an HTTP server?
    By islamfunny in forum CLDC and MIDP
    Replies: 4
    Last Post: 08-15-2008, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •