• 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
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

J2eeCertificate ques

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.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.}

Ans Given: Code compiles, a blank page is displayed.
Explanation:
If you enter an address in the address line of your browser then the HTTP GET method is triggered. The doGet method is not implemented and will use the default value of the HTTPServlet class.

When you want to trigger the HTTP GET method you should override the doGet method. When you have an HTML form and submit it to the server the doPost method is triggered.


But i tried writing a servlet with only a doPost method and accessed it by typing the url and this is what i got
HTTP Status 405 - HTTP method GET is not supported by this URL

type Status report

message HTTP method GET is not supported by this URL

description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).
Apache Tomcat/5.0.28


So is the above answer wrong?
[ March 01, 2005: Message edited by: Sharma Anjali ]
 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Anjali

Please try reading the books first before directly going for checking the output..

If you write method="Post" in the html form then only post method gets fired .Rest in all cases get method gets fired..


Regards
Rohit.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Param=10" is different than "param=10". Look at the Case of the URL variable. That is y the answer gives blank
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it will give you an error when you type the html link because the doGet() didn't define.
 
Sharma Anjali
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rohit Bhagwat:
HI Anjali

Please try reading the books first before directly going for checking the output..

If you write method="Post" in the html form then only post method gets fired .Rest in all cases get method gets fired..


Regards
Rohit.



I think i didn't make my ques clear enough.

When a page is accessed by typing in a url, I know doGet() is called.
So doGet() will be called here.

But i don't have a doGet() defined here only a doPost()

Now the ques askes what will happen if a doGet() is called but there is no doGet() defined.

Explanation says you'll get a blank page because doGet() from super class will run. But when tried it I got a message (as posted above) and not a blank page.
 
Sharma Anjali
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Romy Huang:
I think it will give you an error when you type the html link because the doGet() didn't define.



Exactly that is what I got, but the explanation says it differently and I have seen the same explantion at a number of places.

Can someone plz confirm what should be the right answer.
Although it does look logical that doGet() from super class is called but then why does it give an error ?
 
Sharma Anjali
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any one please
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it may depend on the web container. I use tomcat and I would expect an error stating that doGet has not been defined...
-C
 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly

I also get the error and also I think it is container dependent so I dont think that such questions might appear in the exam..

Worth asking a question in forum
Best of Luck
Regards
Rohit.
 
reply
    Bookmark Topic Watch Topic
  • New Topic