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 ]
Thanks But i did not get different JVMs.swing is in one jvm & servlet in oter.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35438
9
posted
0
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
posted
0
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 .
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.
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.