aspose file tools*
The moose likes Servlets and the fly likes about swing & servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "about swing & servlet" Watch "about swing & servlet" New topic
Author

about swing & servlet

sunanda kadam
Ranch Hand

Joined: Feb 26, 2008
Posts: 42
Hi all,
can we call servlet on swing component as action listener event ?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
That depends on what you mean by "call". A servlet will run in a different JVM than the Swing app, so it's not just a plain old method call. What you can do is make an HTTP request to a URL that's handled by the servlet, and receive its response. Here's an example of how to do that; note that it's possible to pass parameters in the URL if you need to (of course, you need to do proper exception handling as well).
[ July 26, 2008: Message edited by: Ulf Dittmer ]
sunanda kadam
Ranch Hand

Joined: Feb 26, 2008
Posts: 42
Thanks
But i did not get different JVMs.swing is in one jvm & servlet in oter.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42908
    
  69
So you do have different JVMs. Then you need to use the method I outlined above.
sunanda kadam
Ranch Hand

Joined: Feb 26, 2008
Posts: 42
I want to ceeate one swing component & on action event of that component , servlet needs to be invoked.
just as INBOX button in any mail site .
please guide me for this .
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Did you look at the example code that Ulf gave you?
Merely repeating your requirements isn't going to get you a better answer.

Servlets don't get 'called'.
They respond to HTTP requests.
If you want to invoke a servlet from a Swing application, you'll need to generate an HTTP request from the Swing application.

See Ulf's example.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Originally posted by sunanda kadam:
I want to ceeate one swing component & on action event of that component , servlet needs to be invoked.
just as INBOX button in any mail site .
please guide me for this .


Just to follow up on what other people are saying - A Servlet runs on a Server, and Swing runs on a Client. They are, for all intents and purposes different Machines (even if on the same computer, they are on different Java Virtual Machines) so they can't directly talk.

What you can do is make an HTTP Request from the Swing Client to the Server's Servlet and read the response from the Server. This is the only way to communicate with the Servlet.

Read that link to learn the details of how to do said HTTP Request.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about swing & servlet