Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > connect to a servlet

Reply
Thread Tools

connect to a servlet

 
 
raavi
Guest
Posts: n/a
 
      03-12-2007
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

 
Reply With Quote
 
 
 
 
hvt
Guest
Posts: n/a
 
      03-12-2007
On Mar 12, 10:28 am, "raavi" <(E-Mail Removed)> 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.

 
Reply With Quote
 
 
 
 
raavi
Guest
Posts: n/a
 
      03-12-2007
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(PlainSoc ketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.j ava: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.http://www.http.HttpClient.openServe...lient.java:365)
at sun.net.http://www.http.HttpClient.openServe...lient.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.http://www.protocol.http.HttpURLConn...nnection.java:
792)
at
sun.net.http://www.protocol.http.HttpURLConn...nnection.java:
744)
at
sun.net.http://www.protocol.http.HttpURLConn...nnection.java:
669)
at
sun.net.http://www.protocol.http.HttpURLConn...nnection.java:
836)
at ServletConnect.main(ServletConnect.java:56)

 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      03-12-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping session with Servlet to Servlet communications DiscoStu Java 0 07-08-2004 06:50 PM
Offending class: javax/servlet/Servlet.class chamikara Java 1 06-19-2004 05:42 AM
Servlet question(Tomcat, web.xml, servlet-class, servlet-name) circuit_breaker Java 2 04-04-2004 03:26 AM
Tomcat: POST from one servlet or internal class to another servlet Sean Clarke Java 1 01-07-2004 02:22 PM
how to get my servlet configuration before the servlet is initialised Andy Fish Java 4 12-17-2003 09:47 PM



Advertisments