*
The moose likes Servlets and the fly likes How to return a parameter from a servlet to the calling HttpClient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to return a parameter from a servlet to the calling HttpClient" Watch "How to return a parameter from a servlet to the calling HttpClient" New topic
Author

How to return a parameter from a servlet to the calling HttpClient

starfish jellyfish
Greenhorn

Joined: Jun 26, 2011
Posts: 3

I am able to successfully post to a servlet using HttpClient. However i need a boolean parameter back to the HttpClient from the servlet and am not sure how to do the same.

Earleir i was using the common-httpclient-3.1.jar.However then i was made aware of the version upgrade of httpclient to 4.0 which assists in the Response handling from HttpResponse. Now I am using httpclient.4.0.3, httpcore-4.1 and httpmime-4.1.1. The code being tried by me is as below for the HttpClient.



In the KeyStoneServlet i am able to successfully get the parameters directory, username and password. Further using these parameter am doing a further processing and am able to retrieve a boolean parameter which i want back as a response to the HttpClient. However i do not know how can i do the same. The responseBody SOP above comes blank and doesnt show me anything.

In the servlet the parameter i need is mentioned in the below code.



I am unable to understand how should i send this back to the calling httpclient. I understand that i can create a BasicHttpParam in the servlet and use the setBooleanParameter routine. But i cant retreive this param in the calling httpclient.

The SOPs above where i am trying to retrive the params come out blank. Since the SOP for Params returns the defaultValue, it prints out false. The responseBody SOP always comes up as blank

Any immediate assistance on the same will be highly appreciated.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
This servlet side code:



is obviously using some sort of library NOT part of the standard servlet API. Surely the place you should be looking for an answer is the documentation for that library.

A brief search indicates HttpParams are in the Apache httpcomponents library.

Bill
starfish jellyfish
Greenhorn

Joined: Jun 26, 2011
Posts: 3
Hi Will,

I do have httpcore-4.1.jar in my lib. This has the HttpParams as well as the BasicHttpParams class files in them. Do assist me with the same.

Thanks,
starfish
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I never heard of HTTP response parameters before. And I don't see any "setParameter" method in the HttpServletResponse specs either. Normally what people do is to parse the HTTP response to extract the data they need.
starfish jellyfish
Greenhorn

Joined: Jun 26, 2011
Posts: 3
Paul Clapham wrote:I never heard of HTTP response parameters before. And I don't see any "setParameter" method in the HttpServletResponse specs either. Normally what people do is to parse the HTTP response to extract the data they need.


Hi Paul,

I am not mentioning regarding HttpServletResponse. The servlet is being called by a HttpClient and i was looking for a way to read through a boolean parameter which is a response from the servlet to the HttpClient.

I found the needful. Thanks everyone for the assistance. :)

Regards,
starfish
 
 
subject: How to return a parameter from a servlet to the calling HttpClient
 
Similar Threads
Site Authorization using HttpClient: cannot receive cookie.
HttpClient issue on Https Connection (multiple post)
unable to login to a website. tried both httpclient and defaulthttpclient
host unresolved error!!
Manipulating static web pages to get dynamic results!