• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked this in the other post. Please explicitly define what you are trying to save to the DB (and why!)
 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"save the request" is completely ambiguous. I have no idea what you are saving.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
patt rich
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64833
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic