Invoke a Servlet from an Application


Web tier: servlets, JSP, Web frameworks: Invoke a Servlet from an Application

  1. Invoke a Servlet from an Application (5 messages)

    How do you invoke a servlet from an application?

  2. Invoke a Servlet from an Application[ Go to top ]

    You can post to the Servlet.

    See the example code :
         URL url = new URL("http://localhost:8080/examples/servlet/EJBServlet");
    System.out.println(url.toString() + "\n");
                URLConnection con = url.openConnection();
                if (con != null) {
    System.out.println("Able to get Connection to the Server\n");
                ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
                Hashtable inputTable = new Hashtable();
                inputTable.put("key1", "keyValue");

  3. that code is working fine but where to c the output,it is not invoking any browser.........?

  4. If you want to invoke browser you must be accessing from
    an applet.

    The sample code was just to send and receive an object
    from application ( with its own GUI not browser ) to servlet
    and servlet to GUI.

  5. Hi Sam & to everyone,
    I too have a similar question here.
    My servlets are working fine under windows environment(I can invoke them using IE by the following line:-
    Now I want to run the same application in DOS prompt/unix world/main frame world without using a browser,but just only from ordinary java clients(i.e from the command prompt).These java clients will invoke my servlets and the servlets will do the necessary database work(inserting/querying). So should I make use of the URL class for this.Is the sample code you have given sufficient or do I need to make some other changes for it to work.Also if possible could you please kindly give me references on this topic that I could use.
    Thanking You,
  6. The code stub given is sufficient for Applet , Servlet

    References : Java Servlet Programming, Jason Hunter
    ISBN 156592391X