This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

servlet-mapping

 
Ranch Hand
Posts: 34
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both 1 & 2 are correct answers.
 
Bras cause cancer. And tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic