You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by daljeetsingh <da...@softhome.net> on 2001/05/06 18:18:30 UTC

Re[2]: Fw: Velocity within JSP framework

Hello,

Okay if its enlightenment.

On my path to enlightenment I subclassed VelocityServlet and override
the mergeTemplate method to become:

    protected void mergeTemplate( Template template, Context context, HttpServletResponse response )
        throws ResourceNotFoundException, ParseErrorException,
               MethodInvocationException, IOException, UnsupportedEncodingException, Exception
    {
        PrintWriter output = response.getWriter();

        try
        {
            template.merge( context, output);
        }
        catch(Exception ex)
        {
          ex.printStackTrace();
        }
    }
    
 
 and everything works beautifully. But still it will be good to see the
 VelocityWriter being more symmetrical and the velocity servlet not
 closing the output streams. Than that monkey route can be avoided I
 suppose. But wait no, the response.getOutputStream() will still shout
 on TOMCAT which im my subclass now says response.getWriter()


Thanks
Daljeet Singh 
ecExperts India 
Ph:- (O) +91-11-4670906
(R) +91-11-7125680 
ICQ:- 75129600
Yahoo:- daljeetsinghmaken 

Re[2]: Fw: Velocity within JSP framework

Posted by daljeetsingh <da...@softhome.net>.
TOMCAT 3.2

Thanx
Daljeet Singh 


Re: Re[2]: Fw: Velocity within JSP framework

Posted by Nathan Bubna <na...@esha.com>.
> Hi
>
> Yes the response and request I figured about? The issue with them is
> that the context is filled with the key names derived from the following
> static variables:
>
> public static final String REQUEST = "req";
> public static final String RESPONSE = "res";

these strings are final, that means they can't be changed.

>
> If I use $req.getParameter("paramName") and than later the static
> Strings above are changed, I will be in some sort of trouble so is there
> a way I could use VelocityServlet.REQUEST in this case.
>
> Also another related question how do I do
$session.getAttribute("paramName")
> if the HttpSession is in the context object with the key session. I
> guess one solution will be to wrap the session class with a custom
> class. Is there any other way??
>
>
> Thanks,
> Daljeet Singh
> ecExperts India
> Ph:- (O) +91-11-4670906
> (R) +91-11-7125680
> ICQ:- 75129600
> Yahoo:- daljeetsinghmaken
>


Re[2]: Fw: Velocity within JSP framework

Posted by daljeetsingh <da...@softhome.net>.
Hi

Yes the response and request I figured about? The issue with them is
that the context is filled with the key names derived from the following
static variables:

	public static final String REQUEST = "req";
	public static final String RESPONSE = "res";

If I use $req.getParameter("paramName") and than later the static
Strings above are changed, I will be in some sort of trouble so is there
a way I could use VelocityServlet.REQUEST in this case.

Also another related question how do I do $session.getAttribute("paramName")
if the HttpSession is in the context object with the key session. I
guess one solution will be to wrap the session class with a custom
class. Is there any other way??


Thanks,
Daljeet Singh 
ecExperts India 
Ph:- (O) +91-11-4670906
(R) +91-11-7125680 
ICQ:- 75129600
Yahoo:- daljeetsinghmaken 

Re: Fw: Velocity within JSP framework

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
daljeetsingh wrote:
> 
> Hello,
> 
> While running velocity inside a parent JSP page, what are the objects
> that are available in the velocity template without putting them into th
> context object. To be more specific I see that all the turbine users are
> doing something like:
> 
> $data.getSession().getClass().getDeclaredMethods() to perform operation
> on the session.
> 
> Is it possible to access the HttpSession / HttpRequest / HttpResponse
> object without putting them into the context object. If yes, I would
> also like to now what other objects are avialable for a similar kind of
> access.

Yes.  The Velocity servlet will automatically place HttpServletRequest
and HttpServletResponse in the context for you. (see VelocityServlet)

What else is there?

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re[2]: Fw: Velocity within JSP framework

Posted by daljeetsingh <da...@softhome.net>.
Hello,

While running velocity inside a parent JSP page, what are the objects
that are available in the velocity template without putting them into th
context object. To be more specific I see that all the turbine users are
doing something like:

$data.getSession().getClass().getDeclaredMethods() to perform operation
on the session. 

Is it possible to access the HttpSession / HttpRequest / HttpResponse
object without putting them into the context object. If yes, I would
also like to now what other objects are avialable for a similar kind of
access. 


Daljeet Singh 
ecExperts India 
Ph:- (O) +91-11-4670906
(R) +91-11-7125680 
ICQ:- 75129600
Yahoo:- daljeetsinghmaken 

Re: Fw: Velocity within JSP framework

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
"Geir Magnusson Jr." wrote:
> 
> I made the change to VelocityWriter for symmetry, and thinking about the
> removeal of the close() in VelocityServlet, but I want to figure out why
> tomcat has an issue, and what the spec says about this - and do some
> testing.
> 

Update: the VelocityWriter fix is in I believe that indeed the close()
is wrong as you noted, and it should be perfectly safe to ignore it. 
The 2.2 spec doesn't seem to say anything about this.  Will have
resolved any questions today.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Fw: Velocity within JSP framework

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
daljeetsingh wrote:
> 
> Hello,
> 
> Okay if its enlightenment.
> 
> On my path to enlightenment I subclassed VelocityServlet and override
> the mergeTemplate method to become:
> 
>     protected void mergeTemplate( Template template, Context context, HttpServletResponse response )
>         throws ResourceNotFoundException, ParseErrorException,
>                MethodInvocationException, IOException, UnsupportedEncodingException, Exception
>     {
>         PrintWriter output = response.getWriter();
> 
>         try
>         {
>             template.merge( context, output);
>         }
>         catch(Exception ex)
>         {
>           ex.printStackTrace();
>         }
>     }
> 
> 
>  and everything works beautifully. But still it will be good to see the
>  VelocityWriter being more symmetrical and the velocity servlet not
>  closing the output streams. Than that monkey route can be avoided I
>  suppose. But wait no, the response.getOutputStream() will still shout
>  on TOMCAT which im my subclass now says response.getWriter()
> 

I made the change to VelocityWriter for symmetry, and thinking about the
removeal of the close() in VelocityServlet, but I want to figure out why
tomcat has an issue, and what the spec says about this - and do some 
testing.

Which version of tomcat?

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."