• 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

A simple doubt in the usage of GET & POST

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package com.baboon.servletmodel;
2.public class TestParamServlet extends HttpServlet {
3. protected void doPost(HttpServletRequest req,
4. HttpServletResponse resp)
5. throws ServletException, IOException
6. {
7. resp.getWriter().println(req.getParameter("param"));
8. }
9.}

What would be the output in your browser when you invoke the servlet-code with the following URL:
http://localhost/servlet/com.baboon.servletmodel.TestParamServlet?Param=10

1. Code compiles, the output is a blank page with the value 10 printed out.
2. Code compiles, a blank page is displayed.
3. Code compiles, the output is a blank page with null printed out.
4. Code failed compilation, exception IOException is not caught.
5. Code compiles, stacktrace is printed out in browser.


The answer given is No.2., but when i tried a similiar example iam not getting this response.I am actually getting the following error

HTTP Status 405 - HTTP method GET is not supported by this URL

Can anyone let me know the reason for this behaviour.
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When ever you click a link or type in a url the method that gets invoked in your servlet is GET and NOT POST. Since you didn't override the GET method you see the standard error message.
 
Shanmugam Karthikeyan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for your reply .... so does it means that the answer given is wrong.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I created a TestParamSerlvet.java as given in the question and placed in my /Context/WEB-INF/classes folder and also placed the class TestParamServlet in that.

when i tried the same url(context changed) i get the HTTP 404 ....

can we invoke the sevlet directly from the browser without defining in the DD..I dont think so....

correct me if i'm wrong....the question itslef is somewhat vague...or ami getting wrong....can anyone explain.....
 
Rajesh Vijaya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got the doubt cleared myself...i need to configure in the DD...

and karthikeyan ...vat are u getting is correct....

answer no 2 is wrong...as a matter of fact all the answers are wrong....
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since it is a get method , the container will call the doGet() method of the servlet. But it is not overriden in your servlet, the default implementation will get executed and the default implementation for doGet() is 'HTTP 405 message' ( at least in BEA Weblogic).
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Albin Joseph:
Since it is a get method , the container will call the doGet() method of the servlet. But it is not overriden in your servlet, the default implementation will get executed and the default implementation for doGet() is 'HTTP 405 message' ( at least in BEA Weblogic).



Yes exactly albin...the default implementaion of the doGet() will be called by the container.
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I think the proper way of using this is,

override doGet() method and inside that call doPost().That will work out really.

Guys,correct me if I am wrong.

Can anyone suggest me some links for SCWCD Exam.
Thanks a lot
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

can we invoke the sevlet directly from the browser without defining in the DD..I dont think so....


in tomcat, u can just drop ur servlets in tomcat\webapps\ROOT folder and access it as http://localhost/yourServletName
 
Rajesh Vijaya
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi mike ...

I places the test servlet TestParamServlet in ,my Tomcat/webapps/ROOT/ folder

and tried invoking

by http://localhost:8080/TestParamSevlet but i'm getting 404 Error

and i even tried placing the class in Tomcat/webapps/ROOT/web-inf/classes/


but still the same....
 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
override doGet() method
and inside that call doPost().
That will work out really.


ranchers what is teh need of this
overriding doget and then call do post
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means for such questions correct answer will be
HTTP 405 - Resource not allowed

and not the one marked in HFSJ that blank page will be dispplayed.
please correct me if i am wrong.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Since doGet is not overriden in the servlet, HttpServlet.doGet will be called by the container.

As far as Tomcat is concerned, the default behaviour is sending a 405(Method not allowed) error in HTTP 1.1, and a 400(Bad Request) error in HTTP 1.0.
[ December 06, 2005: Message edited by: Satou kurinosuke ]
 
Shanmugam Karthikeyan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

Thanks for all of your response.The example which i have given in my post has a proper configuration in the web.xml, sorry for not specifying this information in the starting itself.

As it is stated in order to prevent these types of error i think we can call a doPost() inside a doGet().

I got this question from www.j2eecerfication.com site.May be i will mail the author so that others won't get confused by this question.
 
reply
    Bookmark Topic Watch Topic
  • New Topic