You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Mike Engelhart <me...@earthtrip.com> on 2000/03/01 05:27:11 UTC

Re: How to process user input in Cocoon?

Milan Zimmermann wrote:

> Hello,
> 
> I am trying to put together a simple (test) Cocoon application with user
> input. 
> 
> I'd like to have a XML file, formatted to HTML using XSLT. Now on the
> resulting HTML, there would be one HTML input field
> 
> <INPUT TYPE=TEXT, NAME="YOUR_EMAIL">
> 
> The Question:
> 
> How do I process the user input into the YOUR_EMAIL field? Do I just
> write a servlet, redirect the result to it and in it's "doPost" method
> do the typical:

> Or is there some other way?
> 
> I cannot find any examples of user-input processing in Cocoon - if
> someone could point me to a URL, that would be helpful as well.
Hey -

Well, it depends on what you are doing.   If there is complex business logic
that needs to be handled using the form data then what I do is use a servlet
to process the request and then forward the resulting data object(s) and
using a RequestDispatcher pass them to an XSP page which in turn generates
an XML sheet.  (RequestDispatcher requires the JSDK 2.1 or higher so if
you're using JServ you'll need to use Tomcat or some other servlet engine)

If you're just getting a few parameters and most of your processing is
simple, you can just call an XSP page directly by having the form be like
this:

<FORM ACTION="/email.xml" METHOD="POST">  <!-- this could be GET too -->
  <INPUT TYPE=TEXT, NAME="YOUR_EMAIL">
</FORM>

Then you can have a file called email.xml that looks like this that handles
everything:

<?xml version="1.0"?>
<?cocoon-process type="xsp"?>
<?cocoon-process type="xslt"?>

<?xml-stylesheet href="email.xsl" type="text/xsl"?>
<xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
    <PAGE>
        <xsp:logic>
            String email = request.getParameter("YOUR_EMAIL")
        </xsp:logic>
        
        <EMAILADDRESS>
            <xsp:expr>email</xsp:expr>
        </EMAILADDRESS>
    </PAGE>
</xsp:page>


Mike


Re: How to process user input in Cocoon?

Posted by Milan Zimmermann <mz...@worldchat.com>.
Mike,

Thanks for your help and code suggestions (and everybody else's
suggestion and code). I hope to have some time this weekend to put
together some test examples, I will post them here for other Ccocoon
newbies like myself [assuming they work of course ;-)]

Thanks, Milan

Mike Engelhart wrote:
> 
> Milan Zimmermann wrote:
> 
> > Hello,
> >
> > I am trying to put together a simple (test) Cocoon application with user
> > input.
> >
> > I'd like to have a XML file, formatted to HTML using XSLT. Now on the
> > resulting HTML, there would be one HTML input field
> >
> > <INPUT TYPE=TEXT, NAME="YOUR_EMAIL">
> >
> > The Question:
> >
> > How do I process the user input into the YOUR_EMAIL field? Do I just
> > write a servlet, redirect the result to it and in it's "doPost" method
> > do the typical:
> 
> > Or is there some other way?
> >
> > I cannot find any examples of user-input processing in Cocoon - if
> > someone could point me to a URL, that would be helpful as well.
> Hey -
> 
> Well, it depends on what you are doing.   If there is complex business logic
> that needs to be handled using the form data then what I do is use a servlet
> to process the request and then forward the resulting data object(s) and
> using a RequestDispatcher pass them to an XSP page which in turn generates
> an XML sheet.  (RequestDispatcher requires the JSDK 2.1 or higher so if
> you're using JServ you'll need to use Tomcat or some other servlet engine)
> 
> If you're just getting a few parameters and most of your processing is
> simple, you can just call an XSP page directly by having the form be like
> this:
> 
> <FORM ACTION="/email.xml" METHOD="POST">  <!-- this could be GET too -->
>   <INPUT TYPE=TEXT, NAME="YOUR_EMAIL">
> </FORM>
> 
> Then you can have a file called email.xml that looks like this that handles
> everything:
> 
> <?xml version="1.0"?>
> <?cocoon-process type="xsp"?>
> <?cocoon-process type="xslt"?>
> 
> <?xml-stylesheet href="email.xsl" type="text/xsl"?>
> <xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
>     <PAGE>
>         <xsp:logic>
>             String email = request.getParameter("YOUR_EMAIL")
>         </xsp:logic>
> 
>         <EMAILADDRESS>
>             <xsp:expr>email</xsp:expr>
>         </EMAILADDRESS>
>     </PAGE>
> </xsp:page>
> 
> Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org

Re: How to process user input in Cocoon?

Posted by Gabor Dolla <ag...@mezon.net>.
> > 
> > I am trying to put together a simple (test) Cocoon application with user
> > input. 
> > 
> > I'd like to have a XML file, formatted to HTML using XSLT. Now on the
> > resulting HTML, there would be one HTML input field
> > 
> > <INPUT TYPE=TEXT, NAME="YOUR_EMAIL">
> > 
> > The Question:
> > 
> > How do I process the user input into the YOUR_EMAIL field? Do I just
> > write a servlet, redirect the result to it and in it's "doPost" method
> > do the typical:
> 
> > Or is there some other way?

Hi

I had a servlet which produced html, it took very little effort to turn it
into a producer which produces xml, then I turn it to HTML with XSL.

Hope this helps

Gabor