Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

connect to a servlet

Thread view: 
raavi - 12 Mar 2007 06:28 GMT
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
hvt - 12 Mar 2007 07:20 GMT
> Hi all,
>    i am doing a web application.in that, i need to call a sevlet from
[quoted text clipped - 8 lines]
> 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.
raavi - 12 Mar 2007 07:36 GMT
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)
Lew - 12 Mar 2007 07:47 GMT
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.