FAQs
Search
Recent Topics
Flagged Topics
Hot Topics
Best Topics
Register / Login
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
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Liutauras Vilda
Devaka Cooray
Jeanne Boyarsky
Bear Bibeault
Sheriffs:
Junilu Lacar
Paul Clapham
Knute Snortum
Saloon Keepers:
Ron McLeod
Tim Moores
Stephan van Hulst
salvin francis
Carey Brown
Bartenders:
Tim Holloway
Frits Walraven
Ganesh Patekar
Forum:
Servlets
Using My Filter for Response Header Settings
Steve Dyke
Ranch Hand
Posts: 1920
1
posted 1 week ago
I am wanting to move some repetitive code into my filter.
In every doPost method of each
Servlet
I have:
response.setHeader( "Pragma", "no-cache" ); response.setHeader( "Cache-Control", "no-cache" ); response.setDateHeader( "Expires", 0 ); response.setCharacterEncoding("UTF-8");
Here is a part of my Filter code to do this. I just want to know it this is the correct way:
private static class SessionAccessAwareResponse extends HttpServletResponseWrapper { public SessionAccessAwareResponse(HttpServletResponse response) { super(response); response.setHeader( "Pragma", "no-cache" ); response.setHeader( "Cache-Control", "no-cache" ); response.setDateHeader( "Expires", 0 ); response.setCharacterEncoding("UTF-8"); } }
Bear Bibeault
Marshal
Posts: 67225
169
I like...
posted 1 week ago
1
Why the response wrapper? Just use a straight-forward servlet filter.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
Post Reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Setting response headers conditionally
WebSphere Portal Cache no store must revalidate no cache
Page Expiry
Cache Control
How to control Caching in JBoss
More...