• 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

ques from j2eecertificate.com

 
Ranch Hand
Posts: 333
  • 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

package com.baboon.servletmodel;
public class TestParamServlet extends HttpServlet
protected void doPost(HttpServletRequest req,
HttpServletResponse resp)throws ServletException, IOException
resp.getWriter().println(req.getParameter("param"));
}
}

The correct answer given is :- Code compiles, a blank page is displayed.

But I think it will throw an exception saying ... Get is not implemented etc !!!

What do u guys think ???
[ November 14, 2004: Message edited by: Giju George ]
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats correct answer. Default service method is doGet() and thats what exacty the URL will try to invoke. No exception is thrown if its not there request is still served. I got that question right when I took that test
Since doPost() is never invoked.. value of 'Param' is never printed from there.

-a.
==========
SCJP 1.4
SCWCD 1.4
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The HTTP method is GET here so there must be an error HTTP 403 ERROR,
Since get is not implemented Iam sure there will be an error shown to teh user,
This method is not supported ....

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

I got the following Error when i tried with out implementing doGet.

Error: 400
Location: /examples/servlet/Param
HTTP method GET is not supported by this URL

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

You would have a better idea if you have a look at the HttpServlet Class. Here the default implementations of all the Http methods are empty. So the code should compile fine and nothing will be printed.

Regards,
Srini
 
Srinivasan Madhavan
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey I am sorry , the default implementation for doGet() method is :

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String protocol = req.getProtocol();
String msg = lStrings.getString("http.method_get_not_supported");
if(protocol.endsWith("1.1"))
resp.sendError(405, msg);
else
resp.sendError(400, msg);
}

So I guess if you donot override this method a 400 error message should appear.

Regards,
Srini
 
Anurag Saksena
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doh! that means I got it wrong

-a.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic