You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by William Stranathan <wi...@thestranathans.com> on 2005/01/25 12:00:04 UTC

OT - Evaulating JSP as internal template?

The subject is prolly a poor way to say what I'm trying to say....

Does anybody know of a simple way to use JSP as an INTERNAL templating 
engine.  For example, if I have a struts application where I'm 
generating an email to send, I currently have to use Velocity on the 
server side to put the values into the template, then send that.

Is there a simple way to do the same with JSP?  Would I be best served 
by on the server side, constructing an HTTP request to a JSP that simply 
pops in the request attributes into the correc place?

High-level of what I want to do:

ActionForward execute(mapping, form, request, response) {
   MyForm myform = (MyForm)form;

   Hashtable vals = new Hashtable();
   vals.put("user",form.getUser());
   vals.put("car",form.getCar());

   JSPProcessor proc = new JSPProcessor();
   proc.getRequestScope().put("values",vals);
   StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");

   MailUtils.mail("admin@xyz.abc.com",buff);
}

Where JSPProcessor is the kind of magic I'm looking for.  I don't really 
see anything built into the API spec, so I SUSPECT if there were 
anything available in Tomcat, for instance, it would be implementation 
specific.

Not a HUGE deal, but it's kinda' a pain to have to train new folks on 
how to put together the JSP's AND how to put together the velocity 
templates.

Thanks,
Will

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Jason Lea <ja...@kumachan.net.nz>.
Oops,

I guess I should add that I was creating email messages during a batch 
processing operation at 1am, so this was not generated by an action, and 
there was no request/response object available.  Otherwise the other 
solution with RequestDispatcher would have worked.

Jason Lea wrote:

>Hi,
>
>I couldn't find a way to do this, other than using Jelly:  
>http://jakarta.apache.org/commons/jelly/
>
>Which uses JEXL which is a EL processing engine, so it looks like JSP 
>with EL.  The Jelly tutorial has an example where you can call the 
>Embedded object to process a jelly script file.  Jelly scripts are not 
>exactly the same though.  I used it for creating some HTML email messages.
>
>William Stranathan wrote:
>
>  
>
>>The subject is prolly a poor way to say what I'm trying to say....
>>
>>Does anybody know of a simple way to use JSP as an INTERNAL templating 
>>engine.  For example, if I have a struts application where I'm 
>>generating an email to send, I currently have to use Velocity on the 
>>server side to put the values into the template, then send that.
>>
>>Is there a simple way to do the same with JSP?  Would I be best served 
>>by on the server side, constructing an HTTP request to a JSP that simply 
>>pops in the request attributes into the correc place?
>>
>>High-level of what I want to do:
>>
>>ActionForward execute(mapping, form, request, response) {
>>  MyForm myform = (MyForm)form;
>>
>>  Hashtable vals = new Hashtable();
>>  vals.put("user",form.getUser());
>>  vals.put("car",form.getCar());
>>
>>  JSPProcessor proc = new JSPProcessor();
>>  proc.getRequestScope().put("values",vals);
>>  StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");
>>
>>  MailUtils.mail("admin@xyz.abc.com",buff);
>>}
>>
>>Where JSPProcessor is the kind of magic I'm looking for.  I don't really 
>>see anything built into the API spec, so I SUSPECT if there were 
>>anything available in Tomcat, for instance, it would be implementation 
>>specific.
>>
>>Not a HUGE deal, but it's kinda' a pain to have to train new folks on 
>>how to put together the JSP's AND how to put together the velocity 
>>templates.
>>
>>Thanks,
>>Will
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> 
>>
>>    
>>
>
>  
>

-- 
Jason Lea



Re: OT - Evaulating JSP as internal template?

Posted by Jason Lea <ja...@kumachan.net.nz>.
Hi,

I couldn't find a way to do this, other than using Jelly:  
http://jakarta.apache.org/commons/jelly/

Which uses JEXL which is a EL processing engine, so it looks like JSP 
with EL.  The Jelly tutorial has an example where you can call the 
Embedded object to process a jelly script file.  Jelly scripts are not 
exactly the same though.  I used it for creating some HTML email messages.

William Stranathan wrote:

>The subject is prolly a poor way to say what I'm trying to say....
>
>Does anybody know of a simple way to use JSP as an INTERNAL templating 
>engine.  For example, if I have a struts application where I'm 
>generating an email to send, I currently have to use Velocity on the 
>server side to put the values into the template, then send that.
>
>Is there a simple way to do the same with JSP?  Would I be best served 
>by on the server side, constructing an HTTP request to a JSP that simply 
>pops in the request attributes into the correc place?
>
>High-level of what I want to do:
>
>ActionForward execute(mapping, form, request, response) {
>   MyForm myform = (MyForm)form;
>
>   Hashtable vals = new Hashtable();
>   vals.put("user",form.getUser());
>   vals.put("car",form.getCar());
>
>   JSPProcessor proc = new JSPProcessor();
>   proc.getRequestScope().put("values",vals);
>   StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");
>
>   MailUtils.mail("admin@xyz.abc.com",buff);
>}
>
>Where JSPProcessor is the kind of magic I'm looking for.  I don't really 
>see anything built into the API spec, so I SUSPECT if there were 
>anything available in Tomcat, for instance, it would be implementation 
>specific.
>
>Not a HUGE deal, but it's kinda' a pain to have to train new folks on 
>how to put together the JSP's AND how to put together the velocity 
>templates.
>
>Thanks,
>Will
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

-- 
Jason Lea




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.3 - Release Date: 2005.01.24


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Thanks Kishore, also good points which I've also added to that page:

 http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html

Niall

----- Original Message ----- 
From: "Kishore Senji" <ks...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Wednesday, January 26, 2005 1:07 AM
Subject: Re: OT - Evaulating JSP as internal template?


> Not anything new, but we can also increase the buffer size
>
> <%@ page buffer="10kb" autoFlush="false" %><%@ taglib
> uri="/WEB-INF/struts-bean.tld"  prefix="bean"  %><bean:define
> id="emailStuff" toScope="request">
>
>       <html>
>          <body>
>              <h1><bean:write name="emailHeading"/></h1>
>              <p><bean:write name="emailBody"/></p>
>          </body>
>       </html>
>
>    </bean:define>
>
>
> Also, if you define your action to extend IncludeAction, then by
> having the path to template in the "parameter"
> you could have the call to RequestDispatcher delegated to
> IncludeAction like so :
>
> public ActionForward execute(ActionMapping mapping,
>                              ActionForm form,
>                              HttpServletRequest request,
>                              HttpServletResponse response) throws
Exception {
>
>         // Set up attributes used by the template
>         request.setAttribute("emailHeading", "Test Heading");
>         request.setAttribute("emailBody", "This is some body text");
>
>         super.execute(mapping, form, request, response); // generate email
>
>         // Get the generated email from the request attribute
>         String emailStuff = (String)request.getAttribute("emailStuff");
>
>         // ...send the email
>
>         // forward to appropriate page
>         return mapping.findForward("success");
>
> }
>
>
>
>
>
> On Tue, 25 Jan 2005 19:00:35 -0000, Niall Pemberton
> <ni...@blueyonder.co.uk> wrote:
> > Good points Kris,
> >
> > hope you don't mind, but I added your comments to the page I set up
> > (although I slightly modified the whitespace *hack*).
> >
> > http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
> >
> > Niall
> >
> > ----- Original Message -----
> > From: "Kris Schneider" <kr...@dotech.com>
> > To: "Struts Users Mailing List" <us...@struts.apache.org>
> >
> > Sent: Tuesday, January 25, 2005 4:32 PM
> > Subject: Re: OT - Evaulating JSP as internal template?
> >
> > > For the paranoid, you probably want to be sure that the email template
> > > ("EmailTestTemplate.jsp") doesn't actually produce any output. Because
> > you're
> > > doing an include followed by a forward, there's a *possibility* that
the
> > > forward will throw an IllegalStateException if the include causes the
> > response
> > > to be committed. You can use one of the various JSP whitespace "hacks"
to
> > > help:
> > >
> > > <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"
%><%--
> > >
> > > --%><bean:define id="emailStuff" toScope="request">
> > >   ...
> > > </bean:define>
> > >
> > > Obviously, the example is unlikely to cause a problem, but a more
involved
> > page
> > > might.
> > >
> > > Another approach might be to pass an HttpServletResponseWrapper to the
> > include
> > > method whose output stream (or writer) just buffers the entire
response
> > for
> > > later retrieval.
> > >
> > > Quoting Niall Pemberton <ni...@blueyonder.co.uk>:
> > >
> > > > You can do this easily using the <bean:define> tag and the
> > > > RequestDispatcher. I've put a page up on my web site showing how:
> > > >
> > > > http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
> > > >
> > > > I believe the RequestDispatcher is the "magic" JSP processor you're
> > looking
> > > > for.
> > > >
> > > > Niall
> > > >
> > > > ----- Original Message -----
> > > > From: "William Stranathan" <wi...@thestranathans.com>
> > > > To: "Struts Users Mailing List" <us...@struts.apache.org>
> > > > Sent: Tuesday, January 25, 2005 11:00 AM
> > > > Subject: OT - Evaulating JSP as internal template?
> > > >
> > > >
> > > > > The subject is prolly a poor way to say what I'm trying to say....
> > > > >
> > > > > Does anybody know of a simple way to use JSP as an INTERNAL
templating
> > > > > engine.  For example, if I have a struts application where I'm
> > > > > generating an email to send, I currently have to use Velocity on
the
> > > > > server side to put the values into the template, then send that.
> > > > >
> > > > > Is there a simple way to do the same with JSP?  Would I be best
served
> > > > > by on the server side, constructing an HTTP request to a JSP that
> > simply
> > > > > pops in the request attributes into the correc place?
> > > > >
> > > > > High-level of what I want to do:
> > > > >
> > > > > ActionForward execute(mapping, form, request, response) {
> > > > >    MyForm myform = (MyForm)form;
> > > > >
> > > > >    Hashtable vals = new Hashtable();
> > > > >    vals.put("user",form.getUser());
> > > > >    vals.put("car",form.getCar());
> > > > >
> > > > >    JSPProcessor proc = new JSPProcessor();
> > > > >    proc.getRequestScope().put("values",vals);
> > > > >    StringBuffer buff =
proc.evaluate("WEB-INF/templates/email.jsp");
> > > > >
> > > > >    MailUtils.mail("admin@xyz.abc.com",buff);
> > > > > }
> > > > >
> > > > > Where JSPProcessor is the kind of magic I'm looking for.  I don't
> > really
> > > > > see anything built into the API spec, so I SUSPECT if there were
> > > > > anything available in Tomcat, for instance, it would be
implementation
> > > > > specific.
> > > > >
> > > > > Not a HUGE deal, but it's kinda' a pain to have to train new folks
on
> > > > > how to put together the JSP's AND how to put together the velocity
> > > > > templates.
> > > > >
> > > > > Thanks,
> > > > > Will
> > >
> > > --
> > > Kris Schneider <ma...@dotech.com>
> > > D.O.Tech       <http://www.dotech.com/>
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > > For additional commands, e-mail: user-help@struts.apache.org
> > >
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Kishore Senji <ks...@gmail.com>.
Not anything new, but we can also increase the buffer size

<%@ page buffer="10kb" autoFlush="false" %><%@ taglib
uri="/WEB-INF/struts-bean.tld"  prefix="bean"  %><bean:define
id="emailStuff" toScope="request">

      <html>
         <body>
             <h1><bean:write name="emailHeading"/></h1>
             <p><bean:write name="emailBody"/></p>
         </body>
      </html>

   </bean:define>


Also, if you define your action to extend IncludeAction, then by
having the path to template in the "parameter"
you could have the call to RequestDispatcher delegated to
IncludeAction like so :

public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response) throws Exception {
        
        // Set up attributes used by the template
        request.setAttribute("emailHeading", "Test Heading");
        request.setAttribute("emailBody", "This is some body text");

        super.execute(mapping, form, request, response); // generate email
        
        // Get the generated email from the request attribute
        String emailStuff = (String)request.getAttribute("emailStuff");
        
        // ...send the email
        
        // forward to appropriate page
        return mapping.findForward("success");
        
}





On Tue, 25 Jan 2005 19:00:35 -0000, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> Good points Kris,
> 
> hope you don't mind, but I added your comments to the page I set up
> (although I slightly modified the whitespace *hack*).
> 
> http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
> 
> Niall
> 
> ----- Original Message -----
> From: "Kris Schneider" <kr...@dotech.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> 
> Sent: Tuesday, January 25, 2005 4:32 PM
> Subject: Re: OT - Evaulating JSP as internal template?
> 
> > For the paranoid, you probably want to be sure that the email template
> > ("EmailTestTemplate.jsp") doesn't actually produce any output. Because
> you're
> > doing an include followed by a forward, there's a *possibility* that the
> > forward will throw an IllegalStateException if the include causes the
> response
> > to be committed. You can use one of the various JSP whitespace "hacks" to
> > help:
> >
> > <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %><%--
> >
> > --%><bean:define id="emailStuff" toScope="request">
> >   ...
> > </bean:define>
> >
> > Obviously, the example is unlikely to cause a problem, but a more involved
> page
> > might.
> >
> > Another approach might be to pass an HttpServletResponseWrapper to the
> include
> > method whose output stream (or writer) just buffers the entire response
> for
> > later retrieval.
> >
> > Quoting Niall Pemberton <ni...@blueyonder.co.uk>:
> >
> > > You can do this easily using the <bean:define> tag and the
> > > RequestDispatcher. I've put a page up on my web site showing how:
> > >
> > > http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
> > >
> > > I believe the RequestDispatcher is the "magic" JSP processor you're
> looking
> > > for.
> > >
> > > Niall
> > >
> > > ----- Original Message -----
> > > From: "William Stranathan" <wi...@thestranathans.com>
> > > To: "Struts Users Mailing List" <us...@struts.apache.org>
> > > Sent: Tuesday, January 25, 2005 11:00 AM
> > > Subject: OT - Evaulating JSP as internal template?
> > >
> > >
> > > > The subject is prolly a poor way to say what I'm trying to say....
> > > >
> > > > Does anybody know of a simple way to use JSP as an INTERNAL templating
> > > > engine.  For example, if I have a struts application where I'm
> > > > generating an email to send, I currently have to use Velocity on the
> > > > server side to put the values into the template, then send that.
> > > >
> > > > Is there a simple way to do the same with JSP?  Would I be best served
> > > > by on the server side, constructing an HTTP request to a JSP that
> simply
> > > > pops in the request attributes into the correc place?
> > > >
> > > > High-level of what I want to do:
> > > >
> > > > ActionForward execute(mapping, form, request, response) {
> > > >    MyForm myform = (MyForm)form;
> > > >
> > > >    Hashtable vals = new Hashtable();
> > > >    vals.put("user",form.getUser());
> > > >    vals.put("car",form.getCar());
> > > >
> > > >    JSPProcessor proc = new JSPProcessor();
> > > >    proc.getRequestScope().put("values",vals);
> > > >    StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");
> > > >
> > > >    MailUtils.mail("admin@xyz.abc.com",buff);
> > > > }
> > > >
> > > > Where JSPProcessor is the kind of magic I'm looking for.  I don't
> really
> > > > see anything built into the API spec, so I SUSPECT if there were
> > > > anything available in Tomcat, for instance, it would be implementation
> > > > specific.
> > > >
> > > > Not a HUGE deal, but it's kinda' a pain to have to train new folks on
> > > > how to put together the JSP's AND how to put together the velocity
> > > > templates.
> > > >
> > > > Thanks,
> > > > Will
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Good points Kris,

hope you don't mind, but I added your comments to the page I set up
(although I slightly modified the whitespace *hack*).

http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html

Niall

----- Original Message ----- 
From: "Kris Schneider" <kr...@dotech.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, January 25, 2005 4:32 PM
Subject: Re: OT - Evaulating JSP as internal template?


> For the paranoid, you probably want to be sure that the email template
> ("EmailTestTemplate.jsp") doesn't actually produce any output. Because
you're
> doing an include followed by a forward, there's a *possibility* that the
> forward will throw an IllegalStateException if the include causes the
response
> to be committed. You can use one of the various JSP whitespace "hacks" to
> help:
>
> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %><%--
>
> --%><bean:define id="emailStuff" toScope="request">
>   ...
> </bean:define>
>
> Obviously, the example is unlikely to cause a problem, but a more involved
page
> might.
>
> Another approach might be to pass an HttpServletResponseWrapper to the
include
> method whose output stream (or writer) just buffers the entire response
for
> later retrieval.
>
> Quoting Niall Pemberton <ni...@blueyonder.co.uk>:
>
> > You can do this easily using the <bean:define> tag and the
> > RequestDispatcher. I've put a page up on my web site showing how:
> >
> > http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
> >
> > I believe the RequestDispatcher is the "magic" JSP processor you're
looking
> > for.
> >
> > Niall
> >
> > ----- Original Message ----- 
> > From: "William Stranathan" <wi...@thestranathans.com>
> > To: "Struts Users Mailing List" <us...@struts.apache.org>
> > Sent: Tuesday, January 25, 2005 11:00 AM
> > Subject: OT - Evaulating JSP as internal template?
> >
> >
> > > The subject is prolly a poor way to say what I'm trying to say....
> > >
> > > Does anybody know of a simple way to use JSP as an INTERNAL templating
> > > engine.  For example, if I have a struts application where I'm
> > > generating an email to send, I currently have to use Velocity on the
> > > server side to put the values into the template, then send that.
> > >
> > > Is there a simple way to do the same with JSP?  Would I be best served
> > > by on the server side, constructing an HTTP request to a JSP that
simply
> > > pops in the request attributes into the correc place?
> > >
> > > High-level of what I want to do:
> > >
> > > ActionForward execute(mapping, form, request, response) {
> > >    MyForm myform = (MyForm)form;
> > >
> > >    Hashtable vals = new Hashtable();
> > >    vals.put("user",form.getUser());
> > >    vals.put("car",form.getCar());
> > >
> > >    JSPProcessor proc = new JSPProcessor();
> > >    proc.getRequestScope().put("values",vals);
> > >    StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");
> > >
> > >    MailUtils.mail("admin@xyz.abc.com",buff);
> > > }
> > >
> > > Where JSPProcessor is the kind of magic I'm looking for.  I don't
really
> > > see anything built into the API spec, so I SUSPECT if there were
> > > anything available in Tomcat, for instance, it would be implementation
> > > specific.
> > >
> > > Not a HUGE deal, but it's kinda' a pain to have to train new folks on
> > > how to put together the JSP's AND how to put together the velocity
> > > templates.
> > >
> > > Thanks,
> > > Will
>
> -- 
> Kris Schneider <ma...@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Will Stranathan <wi...@thestranathans.com>.
Which was one thing I had already done - didn't use comments, but did 
all my up-front work in one line.

w

On Tue, 25 Jan 2005 11:32:41 -0500
  Kris Schneider <kr...@dotech.com> wrote:
>For the paranoid, you probably want to be sure that the email 
>template
>("EmailTestTemplate.jsp") doesn't actually produce any output. 
>Because you're
>doing an include followed by a forward, there's a *possibility* that 
>the
>forward will throw an IllegalStateException if the include causes the 
>response
>to be committed. You can use one of the various JSP whitespace 
>"hacks" to
>help:
>
><%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" 
>%><%--
>
>--%><bean:define id="emailStuff" toScope="request">
>  ...
></bean:define>
>
>Obviously, the example is unlikely to cause a problem, but a more 
>involved page
>might.
>
>Another approach might be to pass an HttpServletResponseWrapper to 
>the include
>method whose output stream (or writer) just buffers the entire 
>response for
>later retrieval.
>
>Quoting Niall Pemberton <ni...@blueyonder.co.uk>:
>
>> You can do this easily using the <bean:define> tag and the
>> RequestDispatcher. I've put a page up on my web site showing how:
>> 
>> http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
>> 
>> I believe the RequestDispatcher is the "magic" JSP processor you're 
>>looking
>> for.
>> 
>> Niall
>> 
>> ----- Original Message ----- 
>> From: "William Stranathan" <wi...@thestranathans.com>
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Sent: Tuesday, January 25, 2005 11:00 AM
>> Subject: OT - Evaulating JSP as internal template?
>> 
>> 
>> > The subject is prolly a poor way to say what I'm trying to say....
>> >
>> > Does anybody know of a simple way to use JSP as an INTERNAL 
>>templating
>> > engine.  For example, if I have a struts application where I'm
>> > generating an email to send, I currently have to use Velocity on 
>>the
>> > server side to put the values into the template, then send that.
>> >
>> > Is there a simple way to do the same with JSP?  Would I be best 
>>served
>> > by on the server side, constructing an HTTP request to a JSP that 
>>simply
>> > pops in the request attributes into the correc place?
>> >
>> > High-level of what I want to do:
>> >
>> > ActionForward execute(mapping, form, request, response) {
>> >    MyForm myform = (MyForm)form;
>> >
>> >    Hashtable vals = new Hashtable();
>> >    vals.put("user",form.getUser());
>> >    vals.put("car",form.getCar());
>> >
>> >    JSPProcessor proc = new JSPProcessor();
>> >    proc.getRequestScope().put("values",vals);
>> >    StringBuffer buff = 
>>proc.evaluate("WEB-INF/templates/email.jsp");
>> >
>> >    MailUtils.mail("admin@xyz.abc.com",buff);
>> > }
>> >
>> > Where JSPProcessor is the kind of magic I'm looking for.  I don't 
>>really
>> > see anything built into the API spec, so I SUSPECT if there were
>> > anything available in Tomcat, for instance, it would be 
>>implementation
>> > specific.
>> >
>> > Not a HUGE deal, but it's kinda' a pain to have to train new folks 
>>on
>> > how to put together the JSP's AND how to put together the velocity
>> > templates.
>> >
>> > Thanks,
>> > Will
>
>-- 
>Kris Schneider <ma...@dotech.com>
>D.O.Tech       <http://www.dotech.com/>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Kris Schneider <kr...@dotech.com>.
For the paranoid, you probably want to be sure that the email template
("EmailTestTemplate.jsp") doesn't actually produce any output. Because you're
doing an include followed by a forward, there's a *possibility* that the
forward will throw an IllegalStateException if the include causes the response
to be committed. You can use one of the various JSP whitespace "hacks" to
help:

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %><%--

--%><bean:define id="emailStuff" toScope="request">
  ...
</bean:define>

Obviously, the example is unlikely to cause a problem, but a more involved page
might.

Another approach might be to pass an HttpServletResponseWrapper to the include
method whose output stream (or writer) just buffers the entire response for
later retrieval.

Quoting Niall Pemberton <ni...@blueyonder.co.uk>:

> You can do this easily using the <bean:define> tag and the
> RequestDispatcher. I've put a page up on my web site showing how:
> 
> http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
> 
> I believe the RequestDispatcher is the "magic" JSP processor you're looking
> for.
> 
> Niall
> 
> ----- Original Message ----- 
> From: "William Stranathan" <wi...@thestranathans.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, January 25, 2005 11:00 AM
> Subject: OT - Evaulating JSP as internal template?
> 
> 
> > The subject is prolly a poor way to say what I'm trying to say....
> >
> > Does anybody know of a simple way to use JSP as an INTERNAL templating
> > engine.  For example, if I have a struts application where I'm
> > generating an email to send, I currently have to use Velocity on the
> > server side to put the values into the template, then send that.
> >
> > Is there a simple way to do the same with JSP?  Would I be best served
> > by on the server side, constructing an HTTP request to a JSP that simply
> > pops in the request attributes into the correc place?
> >
> > High-level of what I want to do:
> >
> > ActionForward execute(mapping, form, request, response) {
> >    MyForm myform = (MyForm)form;
> >
> >    Hashtable vals = new Hashtable();
> >    vals.put("user",form.getUser());
> >    vals.put("car",form.getCar());
> >
> >    JSPProcessor proc = new JSPProcessor();
> >    proc.getRequestScope().put("values",vals);
> >    StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");
> >
> >    MailUtils.mail("admin@xyz.abc.com",buff);
> > }
> >
> > Where JSPProcessor is the kind of magic I'm looking for.  I don't really
> > see anything built into the API spec, so I SUSPECT if there were
> > anything available in Tomcat, for instance, it would be implementation
> > specific.
> >
> > Not a HUGE deal, but it's kinda' a pain to have to train new folks on
> > how to put together the JSP's AND how to put together the velocity
> > templates.
> >
> > Thanks,
> > Will

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Will Stranathan <wi...@thestranathans.com>.
Fantastic!  That's exactly what I was looking for!  And since I've got 
so much stuff in the form bean, I can just access the stuff directly 
from the form bean.  (I know it's not the RIGHT way to do it, but with 
as many attributes as there are to this, it'd be nice to not have to 
rewrite existing stuff.)

Thanks a ton.

Will

On Tue, 25 Jan 2005 13:36:58 -0000
  "Niall Pemberton" <ni...@blueyonder.co.uk> wrote:
>You can do this easily using the <bean:define> tag and the
>RequestDispatcher. I've put a page up on my web site showing how:
>
>http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html
>
>I believe the RequestDispatcher is the "magic" JSP processor you're 
>looking
>for.
>
>Niall

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: OT - Evaulating JSP as internal template?

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
You can do this easily using the <bean:define> tag and the
RequestDispatcher. I've put a page up on my web site showing how:

http://www.niallp.pwp.blueyonder.co.uk/emailTemplate.html

I believe the RequestDispatcher is the "magic" JSP processor you're looking
for.

Niall

----- Original Message ----- 
From: "William Stranathan" <wi...@thestranathans.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, January 25, 2005 11:00 AM
Subject: OT - Evaulating JSP as internal template?


> The subject is prolly a poor way to say what I'm trying to say....
>
> Does anybody know of a simple way to use JSP as an INTERNAL templating
> engine.  For example, if I have a struts application where I'm
> generating an email to send, I currently have to use Velocity on the
> server side to put the values into the template, then send that.
>
> Is there a simple way to do the same with JSP?  Would I be best served
> by on the server side, constructing an HTTP request to a JSP that simply
> pops in the request attributes into the correc place?
>
> High-level of what I want to do:
>
> ActionForward execute(mapping, form, request, response) {
>    MyForm myform = (MyForm)form;
>
>    Hashtable vals = new Hashtable();
>    vals.put("user",form.getUser());
>    vals.put("car",form.getCar());
>
>    JSPProcessor proc = new JSPProcessor();
>    proc.getRequestScope().put("values",vals);
>    StringBuffer buff = proc.evaluate("WEB-INF/templates/email.jsp");
>
>    MailUtils.mail("admin@xyz.abc.com",buff);
> }
>
> Where JSPProcessor is the kind of magic I'm looking for.  I don't really
> see anything built into the API spec, so I SUSPECT if there were
> anything available in Tomcat, for instance, it would be implementation
> specific.
>
> Not a HUGE deal, but it's kinda' a pain to have to train new folks on
> how to put together the JSP's AND how to put together the velocity
> templates.
>
> Thanks,
> Will
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org