• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java application talking to web server  RSS feed

 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to write a Java application using sockets to connect to a web server such as weblogic, and try to retrieve a file from the server machine's certain directory. I have to write a servlet to get requests from the Java application client, and send response containing a data file? Is this the only way to achieve this? What do I need to implement this?
[ July 02, 2003: Message edited by: rick collette ]
 
kris reddy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am assuming that ur client side is an Applet. U have to develop a server side program that listens to the socket requests from the client. In this scenario u can have a dedicated connection between the client and server for transfer of data.
Hope this makes sense.
 
Pearlo Muthukumaran
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
For your case you can easily use URLConnection object of java.net.* package. This can connect to a URL, allow you to open streams and get the content of any MIME type. If your file is a binary file the servlet can serve it with MIME-type - application/octetstream.
I am using this approach for some telecom service applications running 24X7 and it works very well. Jus apply some IO performance tuning tricks like BufferedInputStream and you ll get good results.
Jus goto google and type "URLConnection Examples" and u ll get lotsa examples.
all the best enjoy URLConnection...
Rgds
Muthu
 
rick collette
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys:
These are great hints. I am actually using an plain Java application, not an applet, will that make any difference? In terms of retrieve a particular file from a particular folder, once I connect with a web server (Tomcat for example), how can I access its local file directory? I mean, what is the current directory for the web server, and how to locate a file which is not at the current directory? And could you guys give an example of such a servelet sending out response with binary file to URLConnection?
Thank you very much.
[ July 02, 2003: Message edited by: rick collette ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!