tags:

views:

62

answers:

1

I want to store the result of a JSP in a string.

For example, I want to be able to call a function like:

String result = ProcessJsp("/jspfile.jsp");

Also, this must be rather efficient. Making a url request to the jsp and then storing it would not work because I am running on the Google App Engine, and I'm not sure how slow that would be and also there is a Quota for the number of url fetches you can make.

How could I do this?

Here are my thoughts on how to do this, though I'm not sure if it would work, and I'm hoping there is something simpler:

Do RequestDispatcher("/jspfile.jsp").include(hreq, hresp), but instead of putting the real HttpResponse object in there, you put your own where the getWriter() method returns something that writes to your String or a memory buffer, etc.

+1  A: 

In a comment you state that your goal is caching portions of a JSP page. I'll assume that you're using dynamic includes, rather than client-side requests (eg, Ajax).

If the former, your best solution -- rather than write something yourself -- is to follow the instructions for integrating EHCache into your app-server's stack. Or, if you want to write something yourself, follow the same process but create your own caching filter.

If you want to cache content that will be accessed from the client, then I recommend putting a web-server (such as Apache with mod_cache) in front of your app-server.

Anon
Thanks for the response, do you know what method EHCache uses for getting the result of a JSP?
Kyle
I gave you a link for a reason.
Anon
Just hoping you knew instead of me searching through their source code.
Kyle
If you've already decided that you want to do this on your own, read up on Servlet Filters. That's what EHCache uses.
Anon