connect to a servlet

Discussion in 'Java' started by raavi, Mar 12, 2007.

  1. raavi

    raavi Guest

    Hi all,
    i am doing a web application.in that, i need to call a sevlet from
    a java class.on searching i got the following code.

    URL url=new URL("http://localhost:8080/Scroll_Sample/index.jsp");
    URLConnection conn=url.openConnection();
    conn.setDoInput(false);
    conn.setDoOutput(false);
    i am working on netbeans 5.0 IDE.the above code doesn't work.can
    anyone give me any suggestions? is it possible to connect to a servlet
    from a javaclass?
    Thanks in Advance
    raavi, Mar 12, 2007
    #1
    1. Advertising

  2. raavi

    hvt Guest

    On Mar 12, 10:28 am, "raavi" <> wrote:
    > Hi all,
    > i am doing a web application.in that, i need to call a sevlet from
    > a java class.on searching i got the following code.
    >
    > URL url=new URL("http://localhost:8080/Scroll_Sample/index.jsp");
    > URLConnection conn=url.openConnection();
    > conn.setDoInput(false);
    > conn.setDoOutput(false);
    > i am working on netbeans 5.0 IDE.the above code doesn't work.can
    > anyone give me any suggestions? is it possible to connect to a servlet
    > from a javaclass?
    > Thanks in Advance



    > can anyone give me any suggestions? is it possible to connect to a servlet from a javaclass?

    Yes, using URLConnection or HttpURLConnection. what you are using is
    correct.

    > i am working on netbeans 5.0 IDE.the above code doesn't work.

    What doesn't work in above code, i.e. what error you are getting? how
    are you checking the response code from servlet?
    You can probably browse through the URLConnection API's for available
    method, all required methods are available for reading and writing to
    a servlet, and also for getting servlet response code back.

    Regards.
    hvt, Mar 12, 2007
    #2
    1. Advertising

  3. raavi

    raavi Guest

    the error i am getting is these
    Exception isjava.net.ConnectException: Connection refused: connect
    java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:
    333)
    at
    java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
    at java.net.Socket.connect(Socket.java:507)
    at java.net.Socket.connect(Socket.java:457)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
    at sun.net.www.http.HttpClient.New(HttpClient.java:287)
    at sun.net.www.http.HttpClient.New(HttpClient.java:299)
    at
    sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:
    792)
    at
    sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:
    744)
    at
    sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:
    669)
    at
    sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:
    836)
    at ServletConnect.main(ServletConnect.java:56)
    raavi, Mar 12, 2007
    #3
  4. raavi

    Lew Guest

    raavi wrote:
    > the error i am getting is these
    > Exception isjava.net.ConnectException: Connection refused: connect
    > java.net.ConnectException: Connection refused: connect
    > at java.net.PlainSocketImpl.socketConnect(Native Method)
    > at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:
    > 333)


    That means that the host port is closed. Typically this means that the server
    is not running. It can be complicated by firewall issues.

    -- Lew
    Lew, Mar 12, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Otis Mukinfus
    Replies:
    3
    Views:
    911
    Juan T. Llibre
    Jul 8, 2005
  2. circuit_breaker
    Replies:
    2
    Views:
    1,993
    Jack Jia
    Apr 4, 2004
  3. Replies:
    3
    Views:
    40,216
    Roedy Green
    Nov 16, 2005
  4. Replies:
    2
    Views:
    278
  5. Mohsen Pahlevanzadeh

    Qt connect and first connect or unicode

    Mohsen Pahlevanzadeh, Sep 17, 2013, in forum: Python
    Replies:
    3
    Views:
    152
    Mohsen Pahlevanzadeh
    Sep 18, 2013
Loading...

Share This Page