Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Save a HttpServletResponse  RSS feed

 
Aron Daburn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to copy/save/reproduce a HttpServletResponse object?
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a bad idea.
Why would you want to do this?
What are you trying to accomplish?
 
Aron Daburn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I have a JSP page that is generated which is resulted from reading from a database etc.

What I would 'maybe' like to do is allow a request to go through the first time, copy and save the response, and re-use it for later requests for that page without having to have all of the overhead of going through the process of creating the same page again. It would just instantly send them the already made response instead of continuing on its way to the servlet, grabbing info from the database, etc. (I do realize I will have to strip and replace the cookies)

Is such a concept possible? Is it already implemented in an easy way that I don't know of?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're talking about caching. There are already products that you can run in front of your server to cache frequently-used pages, so you might want to look into them instead of trying to hack together your own.

However, if you have a JSP that always returns the same data, then it really shouldn't be a JSP. It should be a static page, so that web browsers will automatically cache it. If it changes occasionally, because the data changes occasionally, and it's an expensive page to produce, then maybe you should have a process that regenerates the static page as necessary.
 
Aron Daburn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in these products on caching, they will automatically update the cached pages when the information in the database changes?

Generating a static page and forwarding to it while updating the static page when needed is probably a path I could take. I'll have to figure that out. Thanks.
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<<So in these products on caching, they will automatically update the cached pages when the information in the database changes?>>
Updating a cache is complicated business. Especially if there are other ways your table can be updated outside your application (by a dba directly for example). Even if you can guarantee that your app is the only one that is accessing the database one row out of a large table may change. How do you know if that row affects many of the other queries in your system? It can get complicated quickly. I would suggest coding your app first and seeing if/how it can benefit by caching, and then use a cache product that is already available.
 
Aron Daburn
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I ended up writing a filter that checks the page's cached security bean to see if it's 'cacheable'. If it is, on the first request of that page, it sends the request on its way but switches the response with a custom wrapped response. That wrapper class uses a custom output stream which writes the output to both a new file and to the response. The next time the page is requested, the filter just dispatches the request to the much lower cost html page.

Thanks for the help/advice.
 
amit punekar
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Please have a look at OpenSymphony cache.I guess that have some standard way caching the JSPs. Not tried myself but heard it somewhere.

regards
Amit
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!