• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Service method

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to overriede service method, in this method I want to get the method type ( get/post) based on type I will call doGet() or doPost()....

I know its not required to do so if I am already overriding doXXX() but still I want to try it...I want to write same implementation of service() present in HttpServlet in my servlet...

Problem : I am not able to retrieve the method type (get/post) which comes in request.... I don't see any method in ServletRequest which could give me this.... Pls let me know how can I get that?

Thanks in advance !!
[ February 07, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Montano",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Montano Montano:

I am trying to overriede service method, in this method I want to get the method type ( get/post) based on type I will call doGet() or doPost()....



Why? That's exactly what the base service method does. If you are doing this as an academic exercise, there are more useful things you could be learning.

I am not able to retrieve the method type (get/post) which comes in request



It's there. Check the API for the request instance carefully.

Pls let me know how can I get that?



"Pls" is not a word. Please use real words such as "please" when posting to the forums.
 
Montano Mazvik
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply & comments ...
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Montano,

I think you will have to examine the first line of the HTTP request header, most likely by accessing the raw input stream via ServletRequest.getInputStream.readLine(). The HTTP request verb will be the first word of the first line.

This is an academic exercise, right? I mean, HttpServlet.service() already separates the GET and POST verbs for you, so I can't think of any other reason to re-invent that wheel.

Good luck.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Philip Shanks:
I think you will have to examine the first line of the HTTP request heade...



Not correct. The request API provides the needed method.
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Montano MK", thanks for trying to comply with the naming convention, but you're not quite there yet. Your display name must be a first and a last name separated by a space character. Initials for a last name are not acceptable.
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


Not correct. The request API provides the needed method.



Ah, yes. You are right... HttpRequest.getMethod(). Thank you.

But still, if one is overriding service(), they would only have the object as a ServletRequest, with no HTTP methods. They would have to cast it *up* to HttpServletRequest, and this is where the academic approach falters.

To make this a more interesting exercise, one could implement their own HttpServlet class extending javax.servlet.GenericServlet and try implementing the service method there. Then they would be back to examining the HTTP request header in its native state. From the original message, this is what it seemed like Montano was attempting.
[ February 07, 2007: Message edited by: Philip Shanks ]
 
Montano Mazvik
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic