Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need the help

 
viji
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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
 
Bobby Sharma
Ranch Hand
Posts: 598
3
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • 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
 
Subbaiah Annamalai
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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().
 
Ajitabh Mishra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no HelloServlet class. The answer is A.

cheers,
Ajitabh..
 
Ash More'
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
overall the question seems to be incomplete as no mention of web.xml mapping is made.
 
shankar reddy
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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.
 
Prem Kashyap
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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
Google App Engine jQuery Windows
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"vijayalakshmi TH",
Please check your private messages.
-Ben
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"viji",
Please check your private messages regarding an important administrative matter.
-Ben
 
amar kasar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic