My java code needs to pass a memory buffer (containing one complete JSP file) to the JSP engine and retrieve the output of its execution in another memory buffer. Is there some way of acheiving this?

Stacy Curl

I believe the answer to this question is: use a custom tag. If you create a custom tag: removeVowels you can use it in the following way:

<%! private String greeting = "hello";%>
<removeVowels>
<%=greeting%>, this is normal JSP Code that
will get sent to the removeVowels tag class
before being passed to the browser.
</removeVowels>
Here is the removeVowels tag code:

public class RemoveVowelsTag extends BodyTagSupport
{
  public int doStartTag() throws JspTagException
  {
    return EVAL_BODY_TAG;
  }

  public int doAfterBody() throws JspTagException
  {
    try {
      if (bodyContent != null) {
        String voweled = bodyContent.getString();
        String vowelless = removeVowels(voweled);
        bodyContent.getEnclosingWriter().print(vowelless);
      }
    } catch (IOException ie) {}

    return EVAL_PAGE;
  }

  public int doEndTag() throws JspTagException
  {
    return EVAL_PAGE;
  }
}
In your case you would write a tag that took a parameter:
<storeInString name="myString">
blah blah, normal JSP
</storeInString>
<% // Do stuff with 'myString' %>
I'm not sure about how to put the contents of the tag into a variable but I think it's simple, probably something to do with request/response.setParameter

As for the memory buffer part of it, I think that this is asking 'can I process a JSP page that itself was built up dynamically and never existed as a file on the web server' To which I think the answer is: 'Please write it to a file and call it like this':
<storeInString name="myString">
  <jsp:include page="newlyGeneratedFromMemoryBuffer.jsp" flush="true"/>
</storeInString>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact