Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Exam Q

 
Rajesh Krishnan
Greenhorn
Posts: 9
  • 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/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?
 
Mat Williams
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • 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
 
PNS Subramanian
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Sergey Tyulkin
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic