How to store the result of a JSP in a string?
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.
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.
精彩评论