File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to get a response (HTTPServletResponse) to a string? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get a response (HTTPServletResponse) to a string? " Watch "How to get a response (HTTPServletResponse) to a string? " New topic
Author

How to get a response (HTTPServletResponse) to a string?

patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
I have a servlet. The request coming into the servlet has to be saved in a Database.
And the it has to be redirected to a URL.
After it's redirected, I want to get the response to a string which I should ultimately copy to a database.

I am able to :
get the request, save it in the DB, redirect to the URL.

I am not able to :
get the response to a string so that I can save it in the DB.

Any idea how I will do this?

Thanks for your suggestions.


Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

I asked this in the other post. Please explicitly define what you are trying to save to the DB (and why!)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
Thanks for taking interest in the topic.

My aim is to save the request and response in the database table for future reference actually. I store them as varachar in the SQLServer database.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

Still not making sense. My best guess at what you mean is that you want to capture the data which is sent to the response's output stream in the form of a String. Is that anywhere near right?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

"save the request" is completely ambiguous. I have no idea what you are saving.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
patt rich wrote: I am not able to :
get the response to a string so that I can save it in the DB.

The information provided is only leaving us wild guesses. How and what are you trying to get from the response? What all you want from the response? Please set some pointers.

Regards


Experience and talent are independent of age
patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
When I mentioned about saving the request and response, this is what I meant..

Before the HTTPServletRequest is sent out, I have got it in an inputstream and read it to a Stringbuffer. Then I made a string out of it and saved that string in the Database.
Now I decided to send the request object to a URL which is actually hitting a webservice and certain things are happening there.
So, the same way I got the request to a string, I am also expecting that I can get the response object and read that data out to a string and save that in the database.

Does that make any sense? Or am I confusing you guys more?
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
Okay, so it IS actually what you were saying earlier. I was just not able to imagine the "why and how" of the problem and the "what" was something weird.
Anyways, HTTPServletRequest is a request OBJECT. Why you want it to be treated as a string? Or extracted the particular values and appended them to the sb?

patt rich
Greenhorn

Joined: Apr 07, 2008
Posts: 21
I believe the reason why we extracted the content out of it to string is because that was found as the easiest way to store in the database.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Which, in itself, is rather bizarre. What are you storing it for? What is it from the response you want to store? Why?

When you're doing something really bizarre, it's best to give full details.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get a response (HTTPServletResponse) to a string?
 
Similar Threads
sending space separated string in sendRedirect
Get the URL of the page being redirected to?
Why request dispatcher is not sending querystring to jsp?
Need Help With Accessing Multiple Access Database Tables Using JSP
How to create ConfirmServlet using a JavaMail / Servlet Mechanism?