File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet response get output data

 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am required to create a logger which has the values of the data being send for processing as well as the data being send back so that we can diferentiate to find the changes that have been made.
We are using the Strus framework so all the processing goes through a single class.
I have used the request.getParameterMap() and request.getParameter(String paramatername).
However once i pass it to the filter and get the response i am at a loss of how to get the values going in the response.
Do i have to somehow convert the outputstream odf the response into an inputstream and then parse the HTML or something like that? I am totally at a loss. Please advice.
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using filters you can modify both the request and also the response. Please dig into the filter concept properly
 
Sandip Chaudhuri
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI rajesh i looked into the Filter.
but i am not sure exactly what you were referring to.
This is what i have done

PrintWriter out = response.getWriter();
CharResponseWrapper responseWrapper = new CharResponseWrapper(
(HttpServletResponse)response);
chain.doFilter(request, responseWrapper);
StringBuffer str = new StringBuffer(responseWrapper.toString());
out.write(str.toString());

where CharResponseWrapper is

public class CharResponseWrapper extends HttpServletResponseWrapper {
private CharArrayWriter output;

public String toString() {
return output.toString();
}

public CharResponseWrapper(HttpServletResponse response) {
super(response);
output = new CharArrayWriter();
}

public PrintWriter getWriter() {
return new PrintWriter(output);
}
}

Now i have the complete HTML page as a stringBuffer.
But to get the value of the form elements i have to parse etc which i dont think is a great idea since the accuracy goes down quiet a lot.
Am i missing something in the filter or is there any other way?
Thanks for the help.
Sandip
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to use the filter on the servlet that generates the data. This is the servlet that will pass the data that the jsp needs to complete the html.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic