aspose file tools*
The moose likes Servlets and the fly likes Service method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Service method" Watch "Service method" New topic
Author

Service method

Montano Mazvik
Greenhorn

Joined: Feb 07, 2007
Posts: 23
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60996
    
  65

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60996
    
  65

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

Joined: Feb 07, 2007
Posts: 23
Thanks for your reply & comments ...
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
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.


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60996
    
  65

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60996
    
  65

"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

Joined: Oct 15, 2002
Posts: 189
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

Joined: Feb 07, 2007
Posts: 23
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Service method