velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <ge...@optonline.net>
Subject Re: Using Contexts within VelocityServlets
Date Wed, 27 Mar 2002 16:09:11 GMT
On 3/27/02 10:59 AM, "Normand Gagnon" <ngagnon@newtradetech.com> wrote:

> Do you need to have the Velocity Context in session? You can also use the
> request to exchange object between servlets, like:
> 
> request.setAttribute("ctx1",context1);
> 
> context1=(VelocityContext)request.getAttribute("ctx1");

That was my take too... Why use session?  Seems like a request thing...

> 
> 
> 
> At 08:26 AM 3/26/2002 -0500, you wrote:
>> Hello,
>> 
>> I am facing the following problem :
>> 
>> I have a servlet (say Serv1) called from an index.html page.
>> This is the first servlet called when a user connects to my application.
>> This servlet puts some information
>> in the newly created context (say ctx1). Then the template engine
>> contsructs the response html page which
>> allows calling other servlets (Serv2, Serv3, ..) corresponding to
>> services the application provide.
>> The information put by Serv1 in ctx1 is also needed by the other
>> servlets (it has to be passed to the template engine
>> for constructing their responses).
>> So I thought that Context chaining is a solution. The other servlets
>> need to construct a new context this way :
>>          VelocityContext context = new VelocityContext(ctx1);
>> 
>> The question is how can Serv2 get the ctx1 object when treating a
>> request ?
>> 
>> I tested a solution based on the HttpSession object. This object is
>> created when a first request is treated by Serv1 :
>>     HttpSession session = request.getSession(true);
>>     if (session.isNew()) {
>>         session.setAttribute("ctx1", context);
>>     }
>> Also, Serv2 (Serv3, ..) implement createConext() containing the
>> following :
>>     HttpSession session = request.getSession();
>>      VelocityContext context;
>>      if (session != null) {
>>         VelocityContext initialContext =
>> (VelocityContext)session.getAttribute("ctx1");
>>         if (initialContext != null) {
>>             context = new VelocityContext(initialContext);
>>             .............
>> What do you think about this solution ? Has somebody a better idea ?
>> 
>> Adriana
>> 
>> --
>> To unsubscribe, 
>> e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
>> For additional commands, e-mail:
>> <mailto:velocity-user-help@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:
> <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail:
> <mailto:velocity-user-help@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"Now what do we do?"


--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message