• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Modifying the JspWriter Output

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Simon, that sounds a logical solution.

Mark
 
Simon Brown
sharp shooter, and author
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 1913
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Tick check! Okay, I guess that was just an itch. Oh wait! Just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic