Struts2 - How can I get the result of a JSP page as a string in an action class (for emails)

前端 未结 2 1040
我寻月下人不归
我寻月下人不归 2021-01-20 15:06

I want to achieve the 2 things at the same time.

I have a regular jsp page in Struts2. xx/yy/zz/email.jsp




<         


        
2条回答
  •  情书的邮戳
    2021-01-20 15:35

    This is not the answer to your question but I suggest you consider using a template engine to compose your emails, such as Velocity or Jelly

    http://velocity.apache.org/

    http://commons.apache.org/proper/commons-jelly/

    This way you can compose your templates as HTML or XML and inject there any relevant data your logic may have retrieved (and even some logic integrated in their own template languages, such as if-then-else or while-loop structures).

    In the very worst case that is completely necessary to render the full JSP, you could hack something on

    RequestDispatcher::include

    You could execute this method from your MyEmailAction, but passing it a hacked ServletResponse. This would be some class written by you implementing ServletResponse... but writing the result in some ByteArrayOutputStream. After the page is rendered (on your fake ServletResponse) you could just retrieve it from there (actually using the servlet container as your own template engine)

提交回复
热议问题