aspose file tools*
The moose likes Servlets and the fly likes How to send response from a server to a Swing client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to send response from a server to a Swing client" Watch "How to send response from a server to a Swing client" New topic
Author

How to send response from a server to a Swing client

Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Hi all,

I want a response to be send back to the client (Swing application) from the Server (Web application) after all the process of authentication is done on the server side.

The scenario is that I had send the username & password from the swing based login form to the server (AuthenticateServlet.java) and here am doing the authentication for the user to let him login to the swing based application based on the response generated (succes or failure) at the server side.

Can any one help me what are the different ways to achieve this.

Thanks in advance.

K.Anutosh
[ September 30, 2008: Message edited by: Anutosh Swamy ]

K. Anutosh<br /> <br />SCJP 1.4<br />SCWCD 1.4<br />OCA (Paper I)
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
Use the URL and HttpURLConnection APIs.

You're gonna find some method like: setDoInput, setDoOutout, connect, getResponseMessage() and so on...

Long time I do not use these APIs, but they work fine


Regards, Jair Rillo Junior
http://www.jairrillo.com/blog, SCJA 1.0, SCJP 1.4, SCWCD 1.4, SCBCD 5.0, IBM SOA Associate (Test 664).
Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Hi Jair,

See I'd already opened an URL like this at client side

BufferedReader httpbr=null;
String url = "http://localhost:8080/MyApp/loginClient?uid="+user_name+"&pid="+password;

URL opr1_url=new URL(url);
httpbr = new BufferedReader(new InputStreamReader(opr1_url.openStream()));

And from server side I had generated a respose (success or failure).

If failure I need to send two parameters "failure" and "message for the same"

If success I need to send one paramerter "success".

How sholud I send this from server to client and read the same at client side.
Jair Rillo Junior
Ranch Hand

Joined: Aug 27, 2008
Posts: 114
In the servlet, you can use the response object, like in Web application.

In Swing, you can use the getResponseMessage() method (or anything like this, because long time I do not use those APIs).

Certainly in the javadoc or google you'll find more information
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
See this for examples of the client side, especially #135 and #136.

The server side would just be a regular servlet, so you'd use the HttpServletResponse like you would for a browser client (but you wouldn't create HTML, obviously).


Ping & DNS - my free Android networking tools app
Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Thanks Jair
Thanks Ulf

This will definitely solve my issue.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to send response from a server to a Swing client