aspose file tools*
The moose likes Web Services and the fly likes Call Web Service from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Call Web Service from Servlet" Watch "Call Web Service from Servlet" New topic
Author

Call Web Service from Servlet

arriesh chellu
Greenhorn

Joined: Jan 18, 2010
Posts: 7
Hi Folks,
Since i am newbie to web services . i have started developing a simple application which has a login page and have to do its simple validation

For this i created a simple web service which is used for login validation, i have its WSDL link and created the Client...

Now i wanted to use this on my JSP page..Following are the steps i used,

1) Created the Login JSP

2) When Submit button is clicked the Servlet is called

3) This servlet calls the web service by calling its stub and then the respective method(Note: I had included the service and the client jar in my classpath n this is how i get the service)

IDE used : Eclipse Indigo
Server : Tomcat v7

I wanted to ask IS THIS THE CORRECT WAY OF CONSUMING WEB SERVICES USING JSP n SERVLETS..or is their any other way out?
Jimmy Ruts
Greenhorn

Joined: Aug 28, 2012
Posts: 10

I think you should catch your Web service in some backend logic code and parse the result into your JSP. Not directly in your JSP.

I don't even think it is possible??

Just use something like Axis to parse the web service into a backend logic class.

I hope this helps
arriesh chellu
Greenhorn

Joined: Jan 18, 2010
Posts: 7
Jimmy,
Can you please elaborate what do you mean by "parse web service"..?

I am using Apache AXIS 2 and after creating the client and the service projects i have included them in my main project which has the actual web application?

And then in my servlet i get the Stub of the client and then call the respective service method..

I too think its better to leave JSP out of the picture...but there should be some mechanism by which our business logics written in servlets use these web services...

Just wanted to know that the process i followed of including the client and the service jar in the main project is appropriate or not?
Jimmy Ruts
Greenhorn

Joined: Aug 28, 2012
Posts: 10

I think I understand it better now. And If I understand it correctly then I think you are doing a good job.

You have your JSP for the view, you have your Servlet for initialising and generating the things you need to show in a JSP again, and in that Servlet you get your data from your Webservice stub/class.

That seem pretty ok to me.

I am by no means a java Guru or Expert (intermediate at best), but in my opinion this is good. Maybe a more experienced person has something different to say about this...
arriesh chellu
Greenhorn

Joined: Jan 18, 2010
Posts: 7
Thanks Jimmy for the quick reply...

But will need an expert suggetion too on this....

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call Web Service from Servlet
 
Similar Threads
jsp as web service client
Confused on the code implementation generated by the Axis2 Code Generator.
Web Services client using WSDL file
SOAP Proxy - A web service tool that validate SOAP messages
Calling web services from Spring application