You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Rasoul Hajikhani <ra...@rhythm.com> on 2001/09/05 03:57:56 UTC
Overidding doPost & doGet
Hello,
I was wondering if there is any way to explicity override the doPost and
doGet methods within the "handleRequest" of VelocityServlet?
Any help would be welcomed...
-r
Re: Overidding doPost & doGet
Posted by Bojan Smojver <bo...@binarix.com>.
Rasoul Hajikhani wrote:
>
> Hello,
> I was wondering if there is any way to explicity override the doPost and
> doGet methods within the "handleRequest" of VelocityServlet?
> Any help would be welcomed...
> -r
I don't think those methods are final or anything. I think you should be
able to write your own with no issues. It (almost) comes down to writing
your own servlet rather then using VelocityServlet...
But if you go down that path, then doRequest() won't get called from
doGet() and doPost() and therefore handleRequest() won't be called as
well. You'll have to make sure:
- you provide replacements
- call those explicitly
- call the super method (which could be really messy)
Bojan
Re: Overidding doPost & doGet
Posted by Nick Bauman <ni...@cortexity.com>.
Roll your own servlet that has a Velocity in it. That's what I did. There's
no rule that says you must use VelocityServlet.java.
> Hello,
> I was wondering if there is any way to explicity override the doPost
> and doGet methods within the "handleRequest" of VelocityServlet?
> Any help would be welcomed...
> -r
--
Nick Bauman
3600 N. Dupont
Minneapolis, MN 55412
Mobile: (612) 232-7120
SMS: 6122327120@voicestream.net
Home: (612) 522-0165
Re: Overidding doPost & doGet
Posted by Rasoul Hajikhani <ra...@rhythm.com>.
"Geir Magnusson Jr." wrote:
>
> On 9/5/01 11:12 AM, "Rasoul Hajikhani" <ra...@rhythm.com> wrote:
>
> > Jon Stevens wrote:
> >>
> >> on 9/4/01 6:57 PM, "Rasoul Hajikhani" <ra...@rhythm.com> wrote:
> >>
> >>> Hello,
> >>> I was wondering if there is any way to explicity override the doPost and
> >>> doGet methods within the "handleRequest" of VelocityServlet?
> >>> Any help would be welcomed...
> >>> -r
> >>
> >> Is there some valid reason for treating GET and POST requests differently?
> >>
> >> -jon
> >
> > Not really... The question that I was trying to ask was that since
> > handleRequest is sent three parameters when extending VelocityServlet,
> > do doPost & doGet, within the class, get three parameters,
> > HttpServletRequest, HttpServletResponse, and Context? I am not so much
> > concerned with the treatment of the post or get methods, but how doPost
> > and doGet should be called if I am extending VelocityServlet!
>
> The methods doPost() and doGet() are standard methods in the Servlet API,
> and they only get a request and response. Take a look at the source (and
> the API documentation for the Servlet API.)
>
> So you can override them to do what you want - if you just want to hook in
> and do something before the core of VelocityServlet do something, then
> something like
>
> public void doPost( HttpServletRequest request, HttpServletResponse
> response )
> throws ServletException, IOException
> {
>
> /*
> * do your thing here
> */
>
> doRequest(request, response);
> }
>
> Will work just fine.
>
> If you are lazy like me, and don't want to write this once for each doPost
> and doGet(), then just do something like
>
> public void doRequest( HttpServletRequest request, HttpServletResponse
> response )
> throws ServletException, IOException
> {
> /*
> * so your thing here
> */
>
> super.doRequest(request, response);
> }
>
> And all should be well.
>
> Also, as others have noted, there is nothing magic about VelocityServlet -
> you can write your own. The use is that it's well maintained for those of
> us (like myself) that are too lazy to go through all the trouble of writing
> our own. But there are valid reasons.
>
> Forgive the formatting - haven't worked all the kinks out of this yet.
>
> Geir
>
> > -r
Thanks for the response...
-r
Re: Overidding doPost & doGet
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 9/5/01 11:12 AM, "Rasoul Hajikhani" <ra...@rhythm.com> wrote:
> Jon Stevens wrote:
>>
>> on 9/4/01 6:57 PM, "Rasoul Hajikhani" <ra...@rhythm.com> wrote:
>>
>>> Hello,
>>> I was wondering if there is any way to explicity override the doPost and
>>> doGet methods within the "handleRequest" of VelocityServlet?
>>> Any help would be welcomed...
>>> -r
>>
>> Is there some valid reason for treating GET and POST requests differently?
>>
>> -jon
>
> Not really... The question that I was trying to ask was that since
> handleRequest is sent three parameters when extending VelocityServlet,
> do doPost & doGet, within the class, get three parameters,
> HttpServletRequest, HttpServletResponse, and Context? I am not so much
> concerned with the treatment of the post or get methods, but how doPost
> and doGet should be called if I am extending VelocityServlet!
The methods doPost() and doGet() are standard methods in the Servlet API,
and they only get a request and response. Take a look at the source (and
the API documentation for the Servlet API.)
So you can override them to do what you want - if you just want to hook in
and do something before the core of VelocityServlet do something, then
something like
public void doPost( HttpServletRequest request, HttpServletResponse
response )
throws ServletException, IOException
{
/*
* do your thing here
*/
doRequest(request, response);
}
Will work just fine.
If you are lazy like me, and don't want to write this once for each doPost
and doGet(), then just do something like
public void doRequest( HttpServletRequest request, HttpServletResponse
response )
throws ServletException, IOException
{
/*
* so your thing here
*/
super.doRequest(request, response);
}
And all should be well.
Also, as others have noted, there is nothing magic about VelocityServlet -
you can write your own. The use is that it's well maintained for those of
us (like myself) that are too lazy to go through all the trouble of writing
our own. But there are valid reasons.
Forgive the formatting - haven't worked all the kinks out of this yet.
Geir
> -r
Re: Overidding doPost & doGet
Posted by Rasoul Hajikhani <ra...@rhythm.com>.
Jon Stevens wrote:
>
> on 9/4/01 6:57 PM, "Rasoul Hajikhani" <ra...@rhythm.com> wrote:
>
> > Hello,
> > I was wondering if there is any way to explicity override the doPost and
> > doGet methods within the "handleRequest" of VelocityServlet?
> > Any help would be welcomed...
> > -r
>
> Is there some valid reason for treating GET and POST requests differently?
>
> -jon
Not really... The question that I was trying to ask was that since
handleRequest is sent three parameters when extending VelocityServlet,
do doPost & doGet, within the class, get three parameters,
HttpServletRequest, HttpServletResponse, and Context? I am not so much
concerned with the treatment of the post or get methods, but how doPost
and doGet should be called if I am extending VelocityServlet!
-r
Re: Overidding doPost & doGet
Posted by Jon Stevens <jo...@latchkey.com>.
on 9/4/01 6:57 PM, "Rasoul Hajikhani" <ra...@rhythm.com> wrote:
> Hello,
> I was wondering if there is any way to explicity override the doPost and
> doGet methods within the "handleRequest" of VelocityServlet?
> Any help would be welcomed...
> -r
Is there some valid reason for treating GET and POST requests differently?
-jon