Just create a sendmail.jsp which uses the mailer taglib,
then use <jsp:include .../> to include it, it won't generate
any content, just send the email. Pass any parameters
as request scope attributes or using <jsp:param ... />
There are always tradeoffs. Using runtime includes reduces the
memory foot print, but increases the runtime overhead by processing
additional JSP pages. Using the compile time include increases the
memory foot print, but reduces the runtime overhead.
If neither of the above are acceptable, I would try writing a
bean that initializes a static string for the template of the
email body to send. Then use bean properties to set the values
of custom strings to embed in the templated text. To retrieve
the final message body, use a get property. If this were something
you needed to use frequently, create a base class that does this,
then extend it for each different type of data to process.
This would meet your goal of having something that can be
shared across an application without increasing the memory
foot print or incurring the overhead of runtime inclusion of
another JSP page.
Regards,
Glenn
Arun Katkere wrote:
>
> How does this help? I thought you couldn't <jsp:include> inside custom tags
> that access the body (like the mail tag you mention) due to limitations of
> jsp 1.1 (<jsp:include> requires flush to be true) and servlet 2.2 (you
> can't wrap response objects).
>
> i.e., you can' write jsp like:
>
> <mt:mail server="home.net" to="[EMAIL PROTECTED]"
> from="[EMAIL PROTECTED]" subject="mail taglib">
> <mt:message><jsp:include page="foo.jsp" flush="true"/></mt:message>
> <mt:send/>
> </mt:mail>
>
> Of course, you can inline it, but then the only way to achieve reuse (i.e.,
> to access directly or to send it as mail) is with <%@include%>, which is not
> as clean (and result in humongous methods which hit JVM limits).
>
> -arun
>
> > -----Original Message-----
> > From: Glenn Nielsen [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, April 26, 2001 2:12 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: Redirecting the Response of a JSP to a String
> >
> >
> > A fifth solution for just sending email is to use the Mailer taglib at
> > http://jakarta.apache.org/taglibs/mailer/
> >
> > Regards,
> >
> > Glenn
> >
> > Sasha Haghani wrote:
> > >
> > > Hi there,
> > >
> > > ------
> > > DISCLAIMER: This a Tomcat question, where the solution
> > will likely require
> > > some tinkering with the implementation. What I'm to do is
> > probably a
> > > non-standard use case. I think knowledge of the Tomcat internals is
> > > required to answer this. I hope this question is
> > appropriate for this list
> > > -- if not I apologize in advance. Also, sorry for the length...
> > > ------
> > >
> > > I'd like to be able to invoke a JSP on-demand from a Java
> > class and redirect
> > > the response output stream to a String. This could be used
> > to dynamically
> > > generate the body of an e-mail, for instance. The key
> > difference is that
> > > there isn't a *real* corresponding HTTP request or browser
> > socket connection
> > > which would trigger JSP compilation and execution.
> > >
> > > I've come up with 3 potential solutions. Any input or
> > comment on these from
> > > this list is much appreciated.
> > >
> > > ------
> > > SOLUTION 1: Connect to the Servlet Engine like a browser using a
> > > URLConnection object and retrieve the response from there.
> > >
> > > -> This solution is probably the most portable (across
> > Servlet Engines) but
> > > likely isn't the most performant.
> > >
> > > ------
> > > SOLUTION 2: Using Tomcat Interceptors.
> > >
> > > -> I don't know anything about these but would there be
> > anyway to catch and
> > > redirect the response using an Interceptor. I assume such
> > a solution would
> > > only work with Tomcat.
> > >
> > > ------
> > > SOLUTION 3: A custom Interceptor Servlet with a custom
> > Response object.
> > >
> > > -> A custom method could be called on such a GenericServlet
> > and these
> > > servlet would include the body of the JSP using the
> > > RequestDispatcher.include method. A custom Response object
> > would output the
> > > Writer stream to a String or StringBuffer.
> > >
> > > I've attached some sample source code which outlines what I
> > have in mind.
> > >
> > > Could someone give me a reality check on whether this is
> > even feasible or
> > > advisable. Particularly with regard to rolling my own Response
> > > implementation which redirects Writer to a String. Would
> > this kind of
> > > kludge cause any problems for Tomcat?
> > >
> > > ------
> > > Any comments, help or suggestions that anyone can provide
> > are much, much
> > > appreciated. Also, I'd love to hear alternative solutions.
> > Thanks so much.
> > >
> > > Regards,
> > >
> > > Sasha Haghani,
> > > Toronto, Canada.
> >
> > --
> > ----------------------------------------------------------------------
> > Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
> > MOREnet System Programming | * if iz ina coment. |
> > Missouri Research and Education Network | */ |
> > ----------------------------------------------------------------------
> >
--
----------------------------------------------------------------------
Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder |
MOREnet System Programming | * if iz ina coment. |
Missouri Research and Education Network | */ |
----------------------------------------------------------------------