This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

servlet-mapping

 
Paulo Marcio Brandi Rezende
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a mock:

==============

Problem

Which of the following XML codes correctly specify a URL to servlet mapping in the deployment descriptor of a web application?

1.
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog/*</url-pattern>
</servlet-mapping>


2.
<servlet-mapping>
<servlet-name>com.abcinc.CatalogServlet.class</servlet-name>
<url-pattern>/catalog/*</url-pattern>
</servlet-mapping>

3...

4...

==============

The mock says that the right option is #1 and #2 is wrong because:

The value of <servlet-name> tag should be the servlet name defined earlier in a <servlet> tag and not the servlet class name.


But, what is the problem of use com.abcinc.CatalogServlet.class as the servlet's name? If can declare any thing in the <servlet-name>, no?
 
Amandeep Singh
Ranch Hand
Posts: 850
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is as simple as the xml element is

<servlet-name>,

it means it is asking for the servlet name.

if it had been

<servlet-class-name> then your case might be correct of using the package name or class name.

But we can't use it . So using the package name or class name will be aworng answer.

This has been a rule which is hardcoded in the web.xml and the way Container understands this.

Makes Sense?
 
Paulo Marcio Brandi Rezende
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See...

We need to have in web.xml:

<servlet>
<servlet-name>InternalName</servlet-name>
<servlet-class>package.class</servlet-class>
</servlet-mapping>

and:

<servlet-mapping>
<servlet-name>InternalName</servlet-name>
<url-pattern>URLPattern</url-pattern>
</servlet-mapping>

I don't understand why I can not have:

<servlet>
<servlet-name>com.foo.BarServlet</servlet-name>
<servlet-class>com.foo.BarServlet</servlet-class>
</servlet-mapping>

<servlet-mapping>
<servlet-name>com.foo.BarServlet</servlet-name>
<url-pattern>*.foo</url-pattern>
</servlet-mapping>

The container will use the servlet-name internally, and will use it to link a servlet class and a URL, but the container will not make mistake about servlet's name and servlet's class.

It's what I guess...
 
Ramesh Ponnada
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


yes its perfectly valid to give this as servlet name.

And coming to the above question, I guess we are missing something is it the complete question. can you please post the full question.
[ August 07, 2008: Message edited by: Ramesh Ponnada ]
 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The question is asking about the best option and number of options to select must also be given.
 
Paulo Marcio Brandi Rezende
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood that I need choose the correct option, not the best option.

I don't know about the real exam, but in mocks I'm seeing a lot of dubious questions.
 
Paulo Marcio Brandi Rezende
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As requested, the complete question

======================

Question No: 12 (Question ID: 803)
Contributed By: Enthuware


Problem

Which of the following XML codes correctly specify a URL to servlet mapping in the deployment descriptor of a web application?

1.
<servlet-mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog/*</url-pattern>
</servlet-mapping>


2.
<servlet-mapping>
<servlet-name>com.abcinc.CatalogServlet.class</servlet-name>
<url-pattern>/catalog/*</url-pattern>
</servlet-mapping>

3.
<mapping>
<servlet-name>catalog</servlet-name>
<url-pattern>/catalog/*</url-pattern>
<mapping>


4.
<servlet-mapping>
<name>catalog</name>
<url-pattern>/catalog/*</url-pattern>
</servlet-mapping>

5.
<servlet-mapping>
<name>catalog</servlet-name>
<pattern>/catalog/*</url-pattern>
</servlet-mapping>

Options

Select 1 correct option.

========
 
Ramesh Ponnada
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both 1 & 2 are correct answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic