Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mock Question

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A web.xml contains the following element:
<servlet-mapping>
<servlet-name>xyz</servlet-name>
<url-pattern>*Insert code here*</url-pattern>
</servlet-mapping>
Which of the following url-patterns can be put in place of *Insert code here*?

1)*.*
2)/*.*
3)test/*.jsp
4)None of these.

what is the correct answer. I thought answer is 2.

any one can explain.
[ August 06, 2007: Message edited by: PRavi kumar ]
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think answer 2 is correct as the <url-pattern> always starts with '/'.

Please correct me if i am wrong!
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think 4 is the answer.
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Sanjeet ,

can you explain why answer is 4.
 
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am doing something like this

<servlet>
<servlet-name>Servlet1</servlet-name>
<servlet-class>scwcd.Servlet1</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Servlet1</servlet-name>
<url-pattern>*.*</url-pattern>
</servlet-mapping>



It's working fine. Means element is accepting the value.
But not able to make out, which reaquests will be delegated to this.
I thought, it will work as a default servlet. But it's not.
Please someone explain it.

Options 2 and 3 are definitely wrong.
So, answer may be either 1 or 4.

Regards,
Khushhal
 
K Sanjeet
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think 1 is correct

1. url-pattern beginning with '*.' is used for extension match. so '*.*' will work for any url with extension.
2. when a url-pattern starts with contect root its postfix should be '/*' and not '/*.*'
3. its missing the context root '/'

Default servlet is only '/' and not '*.*'

cheers,
sanjeet
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would go with option 2, that says /*.*

Reason: <url-pattern> must start with context root that is "/"
/*.* says any name with any extension.


Please confirm!

I also checked *.*, there is no error but I chose option "2", on behalf
what specification/books say.

Thanks,
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chandra

I am sorry but
Your option is absolutely wrong.
Because for * , a forward slash '/' never comes.

Check your reference.

Regards,
Khushhal
 
khushhal yadav
Ranch Hand
Posts: 242
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christophe,

It means now if I add

<env-entry-name>test</env-entry-name>
<env-entry-value>10</env-entry-value>



to <env-entry> element.

Then when I will use the name test, it will refer to instance of my class which is created by passing "10" as an argument to the class single argument constructor.

And if it a remote component, I do have to register the name test with registeries.

Is it so Christophe??

And Chandra for your problem, I think that will do..

Regards,
Khushhal
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Khushhal,

So what is the correct answer.
Please confirm!

Thanks,
 
Ranch Hand
Posts: 893
Tomcat Server Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure it I think that 1 or 4 is a valid option.

1 is a url-mapping which could be used by extension mapping. *.* could be a wild card for extension mapping, but I think that is not valid, because you have /*

So I would choose 4, but maybe someone could explain why 1 isn't valid.
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only 1 is right..

the url pattern can either contain a path

or

wildcard check as *.* but not both

so test/*.jsp is invalid

only path should begin with /

so /*.* is also invalid.

Another interesting point is *.* will not match anything.

it will not match a.a or a.b or something like that
but will match a.*, test.*, anything.*
so the extension will be a * and thats not a wildcard character.

Hope i have made things clear.


Amol.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Amol Nayak:
[QB]Only 1 is right..

the url pattern can either contain a path

or

wildcard check as *.* but not both



Does specification say this?


it will not match a.a or a.b or something like that
but will match a.*, test.*, anything.*
so the extension will be a * and thats not a wildcard character.


It is quite interesting!


Thanks,
[ August 07, 2007: Message edited by: Chandra Bhatt ]
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure of the specification but will something like this be accepted

/test/*.do

but this will be accepted

/test/*

Please correct if i am wrong..
 
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic