aspose 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
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56230
    
  13

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


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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: 16483
    
    2

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: 56230
    
  13

"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: 56230
    
  13

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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to get a response (HTTPServletResponse) to a string?
 
Similar Threads
Why request dispatcher is not sending querystring to jsp?
Get the URL of the page being redirected to?
Need Help With Accessing Multiple Access Database Tables Using JSP
sending space separated string in sendRedirect
How to create ConfirmServlet using a JavaMail / Servlet Mechanism?