Link to home
Start Free TrialLog in
Avatar of clo1
clo1

asked on

Response in servlet

My client is going to access my servlet function with a specified URL, there is a parameter call RETURN_URL, and he ask me to return the query result in XML format to this RETURN _URL, can anyone give me a clue for how to do it? Thanks !
ASKER CERTIFIED SOLUTION
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clo1
clo1

ASKER

But how do I write the response to the RETURN_URL? I am a bit confuse on this part. Thanks.
You don't return a URL the Servlet will write a response:
OutputStream out=response.getOutputStream()
out.println("<html>");
out.println("<head>");
out.println("<title>Sample Output</title>);
out.println("</head>");
out.println("<body>");
out.println("Now is the time for all good men to come to the aid of their country");
out.println("</body>");
out.println("</html>");
Avatar of clo1

ASKER

But the client does provide a URL for me to return, which is different from the request one. For example, his requesting URL is like this:

http://www.mysite.com/servlet/query?return_url=www.abc.com&keyword=something

So how do I return the result to the return_url parameter, i..e. www.abc.com? Thanks !
SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The best is to use URLEncoder and encode it. I hope you can form a protocol with the client that he can decode it at the other end.

http://www.javaalmanac.com/egs/java.net/Post.html

Also have a look at the "Related Examples".
Redirect will redirect the CLIENT to the URL.  Then the client will get the request from the URL.

If you want to SEND data to the URL use mayankeagle's suggestion.

You will still need to send a response to the client, though.  Just send the remote servers response if it makes sense, or just send "success" or "Failure" pages.
> Redirect will redirect the CLIENT to the URL.  Then the client will get the request from the URL.
>
>If you want to SEND data to the URL use mayankeagle's suggestion.

You can still send data with a redirect.
Yes, you can add additional parameters to the redirect URL and the client will send the additional parameters to the redirect request.
I'd say split the points between all participants.
How about the URLEncoder?
Ah, a max 2-way split.