• 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

Need the help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,

I could get the correct answer.anyone can tell me the output with explanation

package com.javaranch;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class PostServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>\n <body>\n");
out.println(" <h2>\n Hello World\n </h2>\n");
out.println(" </body>\n</html>\n");
out.flush();
out.close();
}
}

What is the result of compiling the above Servlet and accessing it by typing:
"http://www.javaranch.com/test/HelloServlet"
into the address field of a browser

Options
A.The server will not find the Servlet due to an incorrect URL.

B.The browser displays "Hello World"

c.The code fails to compile.

D.An error page is returned from the Server.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

you have to give correct url-mapping in web.xml..

the output of the program is ordinary servlet behaviour...which is contain html code(html instruct browser that how to display the content to the user)

in this program,where you get confuse?

---------------------------------------
Answare is:
The browser displays "Hello World"

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

thanks & regards,
seetharaman.v
 
Ranch Hand
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[UL]
[LI]if you did not set the deployment descriptor ,you will get http 404 error.
[LI]if you did not set your form method as post ,you will get exception.
[UL]

so,the answer is A.

best regards,
omi
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the servlet is mapped correctly in web.xml, then the answer would be

D.An error page is returned from the Server.

Because the default HTTP access method is 'GET' but the program doesnt implement doGet().
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no HelloServlet class. The answer is A.

cheers,
Ajitabh..
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
overall the question seems to be incomplete as no mention of web.xml mapping is made.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ash .. you are correct , Because the question is incorrect , Every one is saying different answer. The Answer is depends on web.xml file.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not think that because web.xml is not shown, then it wont find the servlet.

The fact is when you appear for SCWCD exam, it first clealry explain about the assumption you should make when complete code is not there. In this case, it is to be assumed that web.xml is defined properly.

I mean it doesn't make sense to test your knowledge on missing web.xml file.

The answer is simple. It is D. There is not doGet() defined for the servlet, and hence typing an URL in the browser address bar uses the GET method.

I got this similar question in the real Exam and I am 100% sure the answer is D and they were not testing your alertness that the question does not contain web.xml

And a servlet is mapped using servlet mapping. Which mean you can pass servlet name as "ABC" in the URL whereas the real servlet class name is "XYZ"

Regards
Prem Kashyap
[ May 15, 2008: Message edited by: Prem Kashyap ]
 
Bobby Sharma
Ranch Hand
Posts: 598
3
jQuery Google App Engine Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Ash that the question is incomplete ,At the one it seems the answer is A and the other answers is D.

best regards,
omi
 
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
"vijayalakshmi TH",
Please check your private messages.
-Ben
 
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
"viji",
Please check your private messages regarding an important administrative matter.
-Ben
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic