File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Connecting a Java application to a Servlet/JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Connecting a Java application to a Servlet/JSP" Watch "Connecting a Java application to a Servlet/JSP" New topic

Connecting a Java application to a Servlet/JSP

Kavita Ghia
Ranch Hand

Joined: Oct 10, 2000
Posts: 91
Hello Friends,
I am attempting to make an application in servlets similar to messenger and my problem is how do I connect the clients machine with the servlet once he logs in,since the messengers are basically downloaded products and once u logon and connect your browser gets invoked.
Can anyone help me.Thanking all of u in advance.bye.
Pranav Jaidka
Ranch Hand

Joined: Sep 14, 2000
Posts: 264
hi kavita
1> try creating a URL object with the url of the servlet.
then Using a URLConnection or an HTTPConnection object in which you can pass the url as parameter
for Ex
con = url.openConnection();

2> If the above succeeds (it should if your URL is correct).
then your work is done.
3> do the following as per your rewuirements....
where con is the connection object.
4>now the final stage involves the obtaining of the
input and output streams for the Connection
inputFromServlet = new ObjectInputStream(con.getInputStream());
outputToServlet = new ObjectInputStream(con.getInputStream());
5> your program is ready ....after this you can use the streams to pass the values....(you need to have corresponding streams at the servlet end)
and dont forget to flush the streams to get results at the other end.
Hope this is good enough for you case of any doubts you can mail me at
good luck

inputFromServlet = new ObjectInputStream(con.getInputStream());
I agree. Here's the link:
subject: Connecting a Java application to a Servlet/JSP
It's not a secret anymore!