• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

GET vs POST-Doubt

 
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,
I am having doubt in servlets.
I have one HTML page with form tag. I am sending get request from there.
I have written a servlet class with doPost method and no get method.
IT gives me error while deploying.
my question
1.why is this error.
2. if u say doget has to be there, i say it is there (since i am inheriting from HttpServlet the doGet in the class should come to my class and still why it shows the error.
Explain me please
thanks
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my question
1.WHAT is this error?

can you elaborate, post the error message etc!
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's see if we can turn this into English...

> I am having doubt in servlets.
I am having some questions about servlets.

> I have one HTML page with form tag. I am sending get request from there.
> I have written a servlet class with doPost method and no get method.

actually quite decent

> IT gives me error while deploying.

I doubt the entire IT field would give you AN error, so I assume you mean "I am getting an error during deployment.".

> my question
My questions

> 1.why is this error.
1. Why am I getting this error

> 2. if u say doget has to be there, i say it is there (since i am inheriting from HttpServlet the doGet in the class should come to my class and still why it shows the error.

no clue what you mean here.


> Explain me please

Help me please.

-------------------------------

As Ben said, post the actual error you're getting and maybe someone may be able to help you out.
And for the future: use correct English grammar and spelling, it really makes it easier for others to understand your questions. Not everyone is from India you see, so we don't all have your language background.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeroen,
please don't come into my forum and belittle my visitors. Not all visitors to the 'Ranch have English as their first language and sometimes some interpretation is required.

When you decide to be helpful your posts are of great assistance, but if this is not going to be the case please limit yourself to MD.

Dave
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> 2. if u say doget has to be there, i say it is there (since i am inheriting from HttpServlet the doGet in the class should come to my class and still why it shows the error.

The doGet method that you inherit does nothing but throw an exception, stating that "doGet is not supported".

If you want to support the GET method, you have to override the doGet method.
 
Karthik Rajendiran
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all i really apologize for my poor english.
Thanks for reply.

Let me explain it properly.
Let us assume i am request from a HTML page using GET METHOD in FORM ACTION parameter.
<FORM action = "HelloWorld">
HelloWorld is the Servlet class.
The code for HelloWorld is as follows.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
PrintWriter pw = response.getWriter();
pw.println("hi");

}
}


My Question is as follows. I am requesting from HTML using GET METHOD.
When the servlet gets initialized and service method is invoked on the servlet instance,
the service method calls the doPost or doGet based on my Http Method.

When i tried deploying this in Tomcat, i got HTTP 405 Error
HTTP method GET is not supported by this URL.

Why should i get this error when there is doGet of HttpServlet class and overrided doPost method in HelloWorld.


doPost has nothing to do in this situation as HTTP METHOD used is GET.
By the rule of inheritance we have doGet of HttpServlet in HelloWorld.

I am unable to predict the reason for the error.
Please help me on this.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why should i get this error when there is doGet of HttpServlet class and overrided doPost method in HelloWorld.

Because the default behavior for both the doPost and the doGet methods is to throw an exception stating that "This method is not supported".
If you want to support either of these methods, just override them in your own class.
A simple way to make your servlet behave the same way for GET and POST requests is to override the doGet method as follows:


PS: There is no need to apologize. Your English is much better than my Indian.
[ March 15, 2005: Message edited by: Ben Souther ]
 
Karthik Rajendiran
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ben,
This is karthik and its regarding the servlet clarification.
i have already posted the message in the forum,but needs to get more satisfactory reply.I hope u can give me the answer.

While writing servlet , we extend HttpServlet class,
suppose i request from the HTML with GET Method.

Let HelloWorld be the servlet i have written. It extends HttpServlet.
It has no POST method in it.

I am not calling doGet anywhere in my HelloWorld servlet.


since we extend Httpservlet ,we should get the doGet method of the HttpServlet class in our HelloWorld.

When i deploy i got 405 error, application doesnt not support GET.
Why is this thing.

Wht is the purpose of doGet in HttpServlet. Is it mandatory ot override get.
Explain in detail please.
thanks in advanc
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by karthik rajendiran:


since we extend Httpservlet ,we should get the doGet method of the HttpServlet class in our HelloWorld.


yes, you should and if fact you do get it in your HelloWorld class.



When i deploy i got 405 error, application doesnt not support GET.
Why is this thing.
Wht is the purpose of doGet in HttpServlet. Is it mandatory ot override get.


No, its not mandatory to override this method. But if you dont, you will get get this exception for a get request. Confused ? Ok, let me repeat what Ben has already said



The doGet method that you inherit does nothing but throw an exception, stating that "doGet is not supported".


So if you open your HelloWorld class file with a decompiler, you can see that the inherited doGet method simply throws an exception stating that "doGet is not supported".
hope this helps ..
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by karthik rajendiran:
Hello Ben,
This is karthik and its regarding the servlet clarification.
i have already posted the message in the forum,but needs to get more satisfactory reply.I hope u can give me the answer.

While writing servlet , we extend HttpServlet class,
suppose i request from the HTML with GET Method.

Let HelloWorld be the servlet i have written. It extends HttpServlet.
It has no POST method in it.

I am not calling doGet anywhere in my HelloWorld servlet.


since we extend Httpservlet ,we should get the doGet method of the HttpServlet class in our HelloWorld.

When i deploy i got 405 error, application doesnt not support GET.
Why is this thing.

Wht is the purpose of doGet in HttpServlet. Is it mandatory ot override get.
Explain in detail please.
thanks in advanc




Every time you click on a link, call a webpage from your bookmarks (favorite places, or type the name into your browser's address bar, you are making an HTTP GET request. To make a POST request (or at least, the most common way POST requests are made) is to create an HTML form with the "method" attribute set to "POST" and submit the form.

It's worth Installing Firefox and then adding the

Live HTTP Headers plugin to see the actual request/response headers that get passed between browsers and servers. You'll learn a lot from it.
 
Ranch Hand
Posts: 390
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:
Jeroen,
please don't come into my forum and belittle my visitors. Not all visitors to the 'Ranch have English as their first language and sometimes some interpretation is required.

When you decide to be helpful your posts are of great assistance, but if this is not going to be the case please limit yourself to MD.

Dave



Thanks David for letting Jeron realize this is not EnglishRanch but JavaRanch....No more comment on this.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey karthik,

The doGet() method we get from inheretence need to be overidden to be used in our servlet.By default html sends the request using GET method.
You would have doGet() method from HttpServlet but it would not be useful as no code is written in it to handle your sepecific request.

The server tries to look for your specific doGet() method version in your class and not the doGet() of HttpServlet.With my understanding you need to explicitly override doGet() or else declare mehtod="post" in your html form.

I hope I have answered your question a little bit atleast.
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chaitanya Athanikar:
Hey karthik,

The doGet() method we get from inheretence need to be overidden to be used in our servlet.By default html sends the request using GET method.
You would have doGet() method from HttpServlet but it would not be useful as no code is written in it to handle your sepecific request.

The server tries to look for your specific doGet() method version in your class and not the doGet() of HttpServlet.With my understanding you need to explicitly override doGet() or else declare mehtod="post" in your html form.

I hope I have answered your question a little bit atleast.

 
murali kankanala
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yaa that's right. this answer is suitable as an answer to your question.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by karthik rajendiran:
Hi,

First of all u have to understand why u r extending the HttpServlet Class, if u want any Http Method to be handled in ur servlet better you override the service method,

your container is designed to handled your servlets depending on the Http methods,

once you override the doPost method and not the doGet, your container understands that you are restricting the user by sending the request by GET method, hence the error,

 
no wonder he is so sad, he hasn't seen this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic