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

前端 未结 2 1039
我寻月下人不归
我寻月下人不归 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:27

    I had this problem with using a mailing servlet use this to get the result of the jsp as a string:

    HttpServletResponseWrapper responseWrapper = new HttpServletResponseWrapper(response) {
    private final StringWriter sw = new StringWriter();
    
    @Override
    public PrintWriter getWriter() throws IOException {
        return new PrintWriter(sw);
    }
    
    @Override
    public String toString() {
        return sw.toString();
    }
    };
    request.getRequestDispatcher("email.jsp").include(request,
        responseWrapper);
    String result = responseWrapper.toString();
    

    Set the email to give html content:

    Email.send('me@me.com', 'you@you.com', 'My Subject', result);
    

提交回复
热议问题