You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by El...@tminus10.com on 2000/09/15 21:04:28 UTC

Micke! Re: calling servlet from XML ?

Hello Mike,

Thanks for the reply.  I did see the stuff you mentioned in the archive but
I was hoping to see if it's feasible to control the call from the page
itself (equivalent to server-side includes we do in HTML) for the following
reason:
   We have XML pages in our site that contain static and dynamic data.
Some pages may only need to call one servlet to get dynamic data and embed
   it whereas some page require calling different servlets to get different
set of dynamic information.  With the approach you mentioned, I have to
create
  another servlet to handle these situations and it's not clean.   That's
what I thought the clean way would be to simply acces the XML page itself
and have the
 XML handle the calls to servlet per its needs

 Anyone has run into this problem?  Any other suggestions? etc.



                                                                                                                        
                    Michael                                                                                             
                    Engelhart               To:     cocoon-users@xml.apache.org                                         
                    <mengelhart@eart        cc:                                                                         
                    htrip.com>              Subject:     Re: calling servlet from XML ?                                 
                                                                                                                        
                    09/15/2000 09:54                                                                                    
                    AM                                                                                                  
                    Please respond                                                                                      
                    to cocoon-users                                                                                     
                                                                                                                        
                                                                                                                        



> Hello,
>
> Does anyone know how to call a servlet from an XML file?  In my XML file
> (shown below), I have a section that is static data and a section that is

> dynamic where I want to call a servlet to get data to be inserted in that

> section (my servlet would be outputting XML).  I am assuming that I can
do
> this via XSP tags but I don't know what the syntax or command is to
invoke
> the servlet and get the data.
>
> <mypage>
>    <static-data>
>       .....
>    </static-data>
>    <dynamic-data>
>        <!-- call servlet to get dynamic XML data to be inserted here -->
>   </dynamic-data>
>

Your best bet in this situation is to call the servlet first and the use
RequestDispatcher to stuff the data into the request object and forward it

to the XSP page.  Then you can do something like this:

<dynamic-data>
           <xsp:expr>(Element) request.getAttribute
("dynamicxml")</xsp:expr>
</dynamic-data>

The above syntax depends on if the XML is generated as strings or using
DOM.

If you're using a string then you'd have to import it.

anyway, i've posted this on the mailing list a couple of times so if you
look at the archives there is a more detailed code example.

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-users-help@xml.apache.org






Re: Micke! Re: calling servlet from XML ?

Posted by Michael Engelhart <me...@earthtrip.com>.
Eliza.Khosrova@tminus10.com wrote:

> Hello Mike,
> 
> Thanks for the reply.  I did see the stuff you mentioned in the archive but
> I was hoping to see if it's feasible to control the call from the page
> itself (equivalent to server-side includes we do in HTML) for the following
> reason:
> We have XML pages in our site that contain static and dynamic data.
> Some pages may only need to call one servlet to get dynamic data and embed
> it whereas some page require calling different servlets to get different
> set of dynamic information.  With the approach you mentioned, I have to
> create
> another servlet to handle these situations and it's not clean.   That's
> what I thought the clean way would be to simply acces the XML page itself
> and have the
> XML handle the calls to servlet per its needs
> 
> Anyone has run into this problem?  Any other suggestions? etc.

Unfortunately, I'm not exactly sure what you're trying to do but can't you
do this:

A request comes to a servlet for some dynamic XML generation.  This servlet
figures out which static XML you need and puts the URL to the static page as
well as the dynamically generated XML into the request object and passes the
request object to the XSP which then uses an "include" for the static page
and embeds the dynamic data both of which were passed to it by the
RequestDispatcher.   This also means you only need one XSP since it doesn't
really matter what the data is.  The XSL sheet will determine how's it's
displayed.  Sorry if I'm way off but that's how i'd do it.

MIke