Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to send response from a server to a Swing client

 
Anutosh Swamy
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jair Rillo Junior
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anutosh Swamy
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Anutosh Swamy
Ranch Hand
Posts: 30
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jair
Thanks Ulf

This will definitely solve my issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic