views:

26

answers:

2

i want remove all "\n" for JSP page output.

i think i should be using a Filter for this.

but i dont know how to do

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)throws IOException, ServletException {
      //how to remove all "\n" for output?
}

any idea? thanks for help :)

+4  A: 

BalusC has a post showing such a filter. Check here

This question shows other options for trimming whitespaces.

Bozho
+1  A: 

To get access to the response generated by a resource, you need to wrap the HttpServletResponse object. i.e. change the response object that is passed to the doFilter() method of the FilterChain object. The custom wrapper can buffer up all the output from your resource (JSP/Servlet) which can be accessed and changed before sending it back to the client. You can use simple String.replaceAll() method to replace all \n's.

You can use the HttpServletResponseWrapper class to wrap the response object. Take a look at filter tutorial. This book also gives clear instructions on how to modify a response from a Filter. See section 9.9 of the book.

Suresh Kumar