File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

accessing user input from a web page through a web service

 
ratna sargurp
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am fairly new to java and am trying to code a web service. I have the main logic written and tested locally by hardcoding some values. Now I am trying to do an end to end testing. Here is my scenario:
There is a web application that will be the consumer of my web service. This web app sends me user input through a web page. I read the input, perform my magic, and return the result string back to the web page.

Here is my understanding so far of what I need to do:

1) In order to receive the information from the web page, I need a servlet that gets the parameters from the webpage through request.getParameter on the doGet method. Correct?
2) I then pass this information to my java class that has all the logic.
3) The java class then needs to return this back to the web page.

The method that received the input strings and returns a string has been declared as the web service.

Is this the right understanding? I am kind of stuck at step 3. How do I return this information back to the web page?

Can anybody tell me if I am going in the right direction and guide me?
 
Praful Thakare
Ranch Hand
Posts: 642
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method that received the input strings and returns a string has been declared as the web service.


if you have to invoke this method as webservice then you don't need servlet, simply mark this method as one of Rest methods (POST or GET) and invoke with valid url.

If you follow the approach that you have mentioned then there is no need to mark the method as web service as its not a webservice call its simple servlet call that invoked a method in different class in its doget/post method.

-P
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your web page in the same web app as the web service method? If so, then it's not really a web service, is it?

If not, and the web service result is to be sent back to the still-loaded web page, then the web page needs to use Ajax, not a form submit. A form submit will unload the web page.
 
ratna sargurp
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all your replies.

No the web page is not in the same web app as the web service method. It is an external web page.

Is there any way to simulate this and test my web service manually even before that web page uses my web service?
 
ratna sargurp
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found that SOAP-UI is a wonderful solution to test web services.

Thanks for all your help!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic