How can I call a servlet from a swing application
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Deepak_Mahbubani
Posted On:   Wednesday, December 26, 2001 05:05 AM

I want to call a servlet from a swing client . THis servlet returns a URL to an HTML file it created on the server side.
How can a swing application call a servlet ?

Re: How can I call a servlet from a swing application

Posted By:   Bahar_Limaye  
Posted On:   Wednesday, December 26, 2001 05:17 AM

Any Java application can connect to a URL with the URLConnection class.

An example snippet:

URL servlet = new URL("http://localhost/TestServlet");
URL url = new URL(servlet.toExternalForm());

// Turn off caching
URLConnection con = url.openConnection();
con.setUseCaches(false);

InputStream is = con.getInputStream();
OutputStream os = con.getOutputStream();

// from the input stream, read in the data you need...
About | Sitemap | Contact