Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Mock Question - Servlet Path

Sangita Hota
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on the following information, please construct the full path for the servlet.

Please select one correct answer.

docbase = c:/temp/
context path = /test
alias name = MyMail
servlet-name = com.jiris.common.util.MailServlet
url-pattern = /mail/*

A : c:/temp/mail/com/jiris/common/util/MailServlet.class
B : c:/temp/test/com/jiris/common/util/MailServlet.class
C : c:/temp/mail/test/com/jiris/common/util/MailServlet.class
D : c:/temp/test/mail/com/jiris/common/util/MailServlet.class

I think answer should be "D", but answer is given as "B" and followed by this explanation??


The full servlet path is construted as follows:
full path = docbase + context path + url-pattern + Resource

Accordingly, if I want to enable the user to access this servlet, I should complete the following step:

1. Define the servlet in the web.xml file:

<description>default smtp server address</description>

2. Define the servlet-mapping in the web.xml file:

Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

According to me , the physical path to the servlet should be :


Here c:\temp is the document root base. So from the path it assumed the path for the Window base directory structure. So the slash should be \ not /.

The physical servlet path

docBase+contextPath+\WEB-INF\classes+directory structure as per package+resource.

All the classes reside in WEB-INF\classes directory if not packaged in JARs.

Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!