• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

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 !
0
clo1
Asked:
clo1
  • 4
  • 3
  • 3
  • +1
2 Solutions
 
MogalManicCommented:
Just set the context type to 'text/xml'
  response.setContentType("text/xml");

This must be done before you write the response
0
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now