• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How should I call a servlet from a web service?

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to call a servlet from a web service so I can forward a request to a jsp and display a form to the user, like this:

Jsp1<-->Servlet1<-->W.S.Client<--->WebService<-->Servlet2<-->Jsp2

I can't get Jsp2 to show anything on the screen, and I think it might be because of how I'm calling Servlet2 (URLConnection).

I've had a look round the web, and I can't find any examples of this being done anywhere else.

Any ideas anyone?


Thanks,

Jenny
 
Ranch Hand
Posts: 119
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hope that's what you need

Chapter 12 - Web Services


 
Jenny Goodwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Edson,

Thanks for your contribution. I've had a quick look, but as far as I can see, this article is about creating a JAX-RPC web service, and I'm sorry it's not what I need.

What I should have said in my posting is that I've already got a JAX-WS web service in place. Mea culpa.

The problem lies in trying to invoke a servlet-jsp chain from the web service.


Edson, thanks for taking an interest,

Jenny
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens on the other side of the URLConnection call (such as whether JSP is used or not) is moot. A response is a response. You'll probably need to be more explicit about what's going wrong before any reason for it could be determined.
 
Jenny Goodwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear!

I was right in the middle of reading "Scriptless JSP Pages: The Front Man"! I'm a J2EE newbie, but I was still able to understand what you were saying. Nicely written!

Okay, back to the problem. Here's the diagram again:

Jsp1<-->Servlet1<-->W.S.Client<--->WebService<-->Servlet2<-->Jsp2

The big picture is that a user enters data in a form in Jsp1, and the data is passed up through the chain to the web service.

The requirement is that when the web service receives the data, a second form should be displayed to the user so that further data can be entered before the web service sends a return value back to Servlet1 through the web service client. The only thing I could think of was another Jsp, hence Servlet2<-->Jsp2.

The problem is that when I send data from Jsp1, the screen just goes blank and the browser bar stays at Servlet1 instead of displaying the form in Jsp2.

As I said, I'm new to J2EE, and I don't know if trying to call a servlet from the web service is the best idea. What do you think Bear? Is there a better way of doing this?


Thanks for your comment,

Jenny
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Having a web service try to present a UI to a client makes it not a web service. How, for example, is the web service supposed to know where to show the UI? It has no connection to the original client.

I think you need to rethink your approach.

May be you can give us the real big picture and explain what you are trying to accomplish (not how you are trying to accomplish it).
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The webservice is for doing back-end logic and not suppose to handle the front-end part. You call servlet 2 from servlet 1 itself but use the webservice for logic part.

 
Jenny Goodwin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

First of all, HUGE thanks to Bear and Vinod. I am very grateful for your contributions - I've taken them on board, and I think I've got an idea how this could work...

But first, here's a bigger picture. The system spans two separate web applications - let's call them WebApp1 (Jsp1, Servlet1 and W.S.Client) and WebApp2 (WebService).

Jsp1<-->Servlet1<-->W.S.Client<--->WebService

There are two types of users for this system - let's call them 'TypeA' and 'TypeB'. The user type is identified at the web service.

When the user completes a form in Jsp1, the data is sent through Servlet1 and W.S.Client to the web service. If the web service identifies a TypeA user, data is processed immediately and returned through the web service client to Servlet1 for further action.

However, if the web service identifies a TypeB user, the user should be presented with a second form to complete. The second form has to be hosted by WebApp2. Additionally, the data from this form should be processed in WebApp2 and the result of the processing should be sent to WebApp1.

The only solution I can think of is that when the web service identifies a TypeB user, it should return a URI instead of the processed data result. WebApp1 can then use the URI to redirect the browser to WebApp2.

So, a TypeA transaction would look like this:



The form data entered by the user in Jsp1 is sent through Form1Servlet and the web service client to the web service. As the user type is identified as TypeA, the data is processed, a result is returned through the client to Form1Servlet, and the results are displayed in ResultJsp.

A TypeB transaction would look like this:



The form data entered by the user in Jsp1 is sent through Form1Servlet and the web service client to the web service. As the user type is identified as TypeB, some initial processing occurs and the URI for Form2Servlet is returned through the web service client to Form1Servlet. Form1Servlet identifies the returned data as a URI, and uses it to redirect the browser through Form2Servlet to Form2Jsp where the user enters more data.

When data entry is complete, the form data is processed by System2ResultServlet, the result of the transaction is sent along with a redirect to System1ResultServlet and the results are displayed in ResultJsp.

I've implemented most of this and so far, it seems to work. However, that doesn't mean it's a good strategy. It seems to be very convoluted, and I feel like it's just such a complete... FUDGE! I'm really anxious to get some feedback on this from experienced ranchers, and I'd be very grateful for your opinions.


Thanks,

Jenny
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the nature of the problem I can't see any way to simplify.

Java has all kinds of ways for distributed computing systems to exchange data but if you have to talk to a web service, that restricts your options.

Bill
reply
    Bookmark Topic Watch Topic
  • New Topic