tags:

views:

464

answers:

2

Hello,

I would like to know how is possible to read a file placed in WEB-INF direct into a variable. My intent is to load (and process a page) into a var, than save it to a file and besides that, use the same html result to be displayed (like included) directly into another JSP.

is it possible?

+1  A: 

You can hide jsp pages under WEB-INF which can be <jsp:included>.

Do you expect a caching benefit?

Thorbjørn Ravn Andersen
I would like to read a file just like that <c:set var="body"> <jsp:include page="...jsp"/> </c:set> <cout value="${body}but inside a struts action, what mean no jsp directive. just regular java.
Ruben Trancoso
+2  A: 

You can use a RequestDispatcher.include() method and buffered response. The latter you'll have to write yourself by extending HttpServletResponseWrapper and overriding getWriter() / getOutputStream() methods to return an internal buffer (based on StringWriter, for example). In your servlet, do something like:

MyBufferedResponseWrapper buffer = new MyBufferedResponseWrapper(response); // wrap real response
getServletContext().getRequestDispatcher("path_to_your_jsp").include(request, buffer);
String output = buffer.getOutput();
ChssPly76
interesting, but is request os reponse available in struts action?
Ruben Trancoso
In Struts both are passed as parameters to execute() method: http://struts.apache.org/1.3.10/apidocs/org/apache/struts/action/Action.html. In Struts2 both are available from ServletActionContext: http://struts.apache.org/2.1.6/docs/how-can-we-access-the-httpservletrequest.html
ChssPly76