2 Replies Latest reply on Apr 4, 2006 4:49 AM by Alexander Fedorenko

    create mail from a JSP content

    gmeroz Newbie

      i want to send an email which content is rendered by a JSP. In addition i want to change the tag created by the JSP to another URL.

      is it possible from a JSP to send it's result to a servlet that will convert the URL and send them by mail?

        • 1. Re: create mail from a JSP content
          Alexander Fedorenko Newbie

          Actually it could be implemented with wrapper


          /**
          *
          * Get generated page body as String.
          * Using :
          *
          *
          * JspResponseWrapper my = new JspResponseWrapper(response) ;
          * request.getRequestDispatcher( request.getContextPath() + "/index.jsp" ).include(request, my);
          * String body = my.getBody() ;
          *
          *
          */



          public class JspResponseWrapper extends javax.servlet.http.HttpServletResponseWrapper {

          StringWriter sw ;

          public JspResponseWrapper(javax.servlet.http.HttpServletResponse response) {
          super(response) ;
          sw = new StringWriter() ;
          }

          public PrintWriter getWriter() throws IOException {
          PrintWriter pw = new PrintWriter(sw) ;
          return pw ;
          }

          public String getBody() {
          return sw.toString() ;
          }

          }

          • 2. Re: create mail from a JSP content
            Alexander Fedorenko Newbie

            Code example :


            JspResponseWrapper my = new JspResponseWrapper(response) ;
            request.getRequestDispatcher( request.getContextPath() + "/index.jsp" ).include(request, my);
            String body = my.getBody() ;

            // and send mail now