• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Mock Exam Q

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/util/MailServlet.class
B : c:/temp/test/mail/com/jiris/util/MailServlet.class
C : c:/temp/test/mail/util/MailServlet.class
D : c:/temp/test/com/jiris/util/MailServlet.class


The answer given is B.
REason specified is
he full servlet path is construted as follows:

full path = docbase + context path + url-pattern + Resource

Is this correct? Isnt the url-pattern a virtual path?
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Url-pattern just matches what you type in the address bar or what a page uses in an <a href=""></a> tag to the actual servlet doing the work.
So B is the most correct answer. I will add that b should read
c:/temp/test/mail/com/jiris/common/util/MailServlet.class not

c:/temp/test/mail/com/jiris/util/MailServlet.class


if the servlet is in the package "com.jiris.common.util"

HTH

Matt
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a question here - i specify my <url-pattern> as "asdf" and i do not have any such folder in my file system. In this case how do we include <url-pattern> as a part of the full path ?



The full path of the servlet is
\webapps\ROOT\WEB-INF\src\com\servlet\TestServlet.java

The declaration in DD is
<servlet-mapping>
<servlet-name>Test1</servlet-name>
<url-pattern>/asdf</url-pattern>
</servlet-mapping>



I am not very sure if <url-pattern> would be a part of the full path.
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

your <url-pattern> of "asdf" does not appear in the path to the actual class file at all.
the <url-pattern> is used to map (hence the tag <servlet-mapping> what the user types in to the address bar with the name of the servlet that the user is requesting.



given the web.xml fragment above, if the user types in <a href="http://localhost:8080/webapp<b rel="nofollow">/Baz</b>" target="_blank">http://localhost:8080/webapp/Baz the servlet container will map this request to the servlet named Bar and then will see that this is should be processed by the servlet com.servlets.Foo

Thus the url-pattern tag has nothing to do with the full path of the servlet. The servlet will be located in .../webapp/WEB-INF/classes/com/servlets/Foo.class

HTH

Mat
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matt, I think Rajesh understand the things you said.

The question is: Why the correct answer uses url-pattern to construct the full path to the Servlet?

I wonder, if this mock exam is correct itself ....
For example,
servlet-name = com.jiris.common.util.MailServlet
Note: servlet-name, not servlet-class. So we can make no assumptions about the servlet class itself.

Rajesh. can you give me the link to the mock?
 
reply
    Bookmark Topic Watch Topic
  • New Topic