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 !
LVL 2
clo1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
Just set the context type to 'text/xml'
  response.setContentType("text/xml");

This must be done before you write the response
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
clo1Author Commented:
But how do I write the response to the RETURN_URL? I am a bit confuse on this part. Thanks.
0
MogalManicCommented:
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>");
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

clo1Author Commented:
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 !
0
girionisCommented:
You can either redirect the flow to the requested URL or you can initiate a new POSt request to the provided URL. For first case you can use:

response.sendRedirect(<your url>);

or even a request dispatcher. For second case have a look here: http://www.javaworld.com/javaworld/javatips/jw-javatip34.html
0
Mayank SAssociate Director - Product EngineeringCommented:
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".
0
MogalManicCommented:
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.
0
girionisCommented:
> 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.
0
MogalManicCommented:
Yes, you can add additional parameters to the redirect URL and the client will send the additional parameters to the redirect request.
0
girionisCommented:
I'd say split the points between all participants.
0
Mayank SAssociate Director - Product EngineeringCommented:
How about the URLEncoder?
0
Mayank SAssociate Director - Product EngineeringCommented:
Ah, a max 2-way split.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.