• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modifying the JspWriter Output  RSS feed

 
Mark Nicholas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to modify / filter the output of the JspWriter for a JSP page such that some transformation can take place before the output is sent to the client browser.
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. As you know, content written from the JSP page goes straight to the JspWriter, and hence back to the client.
A simple way to modify the content, is to use a special type of custom tag (called a "body tag") to wrap up the content that you want to filter. For example:

Essentially, the <filter> tag can capture the content generated between inside its body, which can then be manipulated before being properly outputted to the actual JspWriter instance.
The technical details around how all this works aren't that tricky, but there is a fair amount of explanation around it. Rather than summarise it here, for full details with examples including a tag that filters HTML characters on page 163, take a look at Chapter 6, "Body Tags" (from Professional JSP Tag Libraries) which is free to download in PDF format.
Hope that helps.
Simon
[ July 22, 2002: Message edited by: Simon Brown ]
 
Mark Nicholas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Simon, that sounds a logical solution.

Mark
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just had a thought - if you're after something a little more coarse-grained then check out how you can perform post-processing with filters.
Cheers
Simon
 
Mark Nicholas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know about filters, but what I'd like to achieve is compress the output: 1) strip away whitespace, and linefeeds 2) possible gzip compression.

Thoughts ?
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Filters then, as you can apply it to either JSPs or Servlets. The tag solution is great for filtering specific fragments of JSP, but filters allow you to post-process the entire response.
 
Mark Nicholas
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simon,
That sounds great, when I said I knew about filter, a passing glance.
Thanks for all your advice.
Mark
 
chanoch wiggers
Author
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is probably a filter written already that compresses the response, this is a very common requirement
- maybe I should say "generic" requirement, reusable
[ July 24, 2002: Message edited by: chanoch wiggers ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!