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 ]