This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Invoking web service from a .jsp  RSS feed

 
Manuel Gavilan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everyone!

You see, i'm having some trouble with my thesis.

I need to communicate a web developed in .jsp with a web service. I've been watching some tutorials and i have created the .java method which just gets a parameter and returns an answer "The parameter is: <parameter>".

I have created the web service server and i have found the wsdl and from here i'm lost.

All i want to do is to POST from a simple form the parameter, i want my ws to get that parameter, process is with the method and return and answer to the web site.

I'll try to be more specific:

1. In the form, which file do i have to write in the action field? the wsdl? the .java? (yeah, i'm a beginner in web services, please be patient)

<form action=??? method="POST>

2. Once i post the parameter to that file how do i get it and invoke the method with that parameter?

3. How do i answer the web site? When i write "return" in the method does it answer the page automatically?

If you help me i'll be eternally grateful to all of you. Thank you.>
 
Manuel Gavilan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You see... i process it the local way, just calling the method inserting it on the <% %> labels in html but for my thesis i need to work on a web service.

I know i'm a noob but it is just that i have no idea how to do this. You can call me whatever you like, but please, help me if you can.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really a job for code in a JSP as many people will tell you.

Instead, create a "helper" class that can be tested outside the JSP/servlet environment. When you have that running and well debugged, then think about using it in your JSP.

Trying to develop anything complicated entirely in the servlet/jsp environment just leads to frustration. Recall that you can add a main() method to any Java class so it can be tested from the command line.

Bill
 
Manuel Gavilan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:Not really a job for code in a JSP as many people will tell you.

Instead, create a "helper" class that can be tested outside the JSP/servlet environment. When you have that running and well debugged, then think about using it in your JSP.

Trying to develop anything complicated entirely in the servlet/jsp environment just leads to frustration. Recall that you can add a main() method to any Java class so it can be tested from the command line.

Bill


Do you reccomend me to create a java client for the web service and integrate it in the .jsp?

Huh, that would be easy, but the communication has to be in SOAP format, you see...

I have the worst teacher in the world and he doesn't help me at all and i haven't ever worked in web services. I have worked with HTML and what not, but i haven't ever used ws. That's why i have this problems.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you reccomend me to create a java client for the web service and integrate it in the .jsp?

Yes, at the very least use a backing bean in your JSP which contains the Java code to connect to the WS.

I don't understand what you mean by "but" in "but the communication has to be in SOAP format", or what that has to do with keeping the code to do it in a backing bean.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Groan, if you also have to cope with SOAP, you really need to start outside the JSP environment. SOAP client toolkits are all over the place but they typically involve creating lots of classes to build a SOAP formatted request and interpret a SOAP formatted response. Hard enough even without JSP/servlet environment.

The tiny bit of good news is - if the SOAP service does not require all the spiffy WS-* security, AND you can get a text example of a correct SOAP request, you may be able to cheat.

Using an existing SOAP message as a template, you can plug in your own values and send the request. You will have to roll your own SOAP response parsing with standard XML tools. This cuts out all sorts of SOAP client confusion.

Note, none of this is done in Java code in the JSP! Just erase that idea from your mind - see Ulf's backing bean comment.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!