This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to invoke my servlet from a third party web client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to invoke my servlet from a third party web client" Watch "how to invoke my servlet from a third party web client" New topic
Author

how to invoke my servlet from a third party web client

Venkat Pakanati
Greenhorn

Joined: Jul 13, 2011
Posts: 7
How to invoke my servlet from a third party web client which gives a request parameter of url to my servlet.

Basically the request coming from a web application will send a URL, to my servlet. How to handle that.

And also how can I send the response back without redirecting the user to a different url, the user should be able to do what ever he wants, meaning he should not be taken to any other page for response. It should be sent to the user directly and also uniquely.

Can anyone help me, please.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

From which point of view? The target application doesn't have to do anything special, a request is simply a request. It doesn't matter where its coming from.

Or, is your question regarding how to initiate the request in the first place? If so, we need more info on the requirements.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Venkat Pakanati
Greenhorn

Joined: Jul 13, 2011
Posts: 7
Yes, I need to know how can the third party web client should initiate my servlet.

The scenario is that

There is a button which is clicked, this button should invoke my servlet, from where I should take a request URL, given by that button click, which will have some parameters that I need to query to database and render the data to Excel and send this excel as response to user, without redirecting to any other url. Just Excel sheet should popup. For Happy Scenario.

If error, then can I give them a window popup saying error. Please let me know how to do window popup.

Please let me know if you need any more information.

Thanks.
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 81

You can do it easily, just like http://youripordomainnam:port/ServletName?anyparameters
Venkat Pakanati
Greenhorn

Joined: Jul 13, 2011
Posts: 7
Thanks, for the reply.

So the url will be there in the request and I just have to take the query string from the url. But how can I return the response back to the unique user's request.

I did this.

RequestDispatcher requestDispatcher = this.getServletContext().getRequestDispatcher("/servlet");

requestDispatcher.include(request, response);

Is it correct.

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

Again, just like any other servlet. Why do you think you need to do anything special?
Venkat Pakanati
Greenhorn

Joined: Jul 13, 2011
Posts: 7
Because, I have a requirement which says that the excel sheet in the response of servlet should be opened without the user redirected to any other url.

Like, Forward method on servlet. Can you please let me know how can I do that. I have done this to open the response in an Excel sheet

response.setHeader("Content-Type", "application/vnd.ms-excel");
response.setHeader("Content-disposition", "inline; filename="+fileName+"-"+legacyDocNbr+".xls");

Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

How the response is handled once you send it with its headers is up to the client, not the servlet.
Venkat Pakanati
Greenhorn

Joined: Jul 13, 2011
Posts: 7
Ok, so If I want to test this using ServletUnit. Can you give an example how can I unit test my servlet.

Thanks.
Venkat Pakanati
Greenhorn

Joined: Jul 13, 2011
Posts: 7
Ok, my Unit test works.

But I want to see the Excel sheet coming up. When manually enter the url for my servlet in browser it gives me 404 response.

Can some one please let me know how can I do that.

Thanks.
 
 
subject: how to invoke my servlet from a third party web client
 
Similar Threads
IBM HttpServer and websphere Appserver
Xml document as a SOAP payload
Chapter 2 (HFSJ) notes , may be useful for anyone
How to handle an asynchronized scenario?
problem while giving a url pattern in filter mapping