*
The moose likes Servlets and the fly likes Giving same name for URL pattern in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Giving same name for URL pattern in web.xml" Watch "Giving same name for URL pattern in web.xml" New topic
Author

Giving same name for URL pattern in web.xml

swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
Hi Rancher
Can we give the same name to URL pattern that already has been given?
If yes which resouce is sent back to client?Please Help
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why would you want to do such a thing?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
Interviewer asked me this question and excepting detail answer
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Did you try it?
What happened?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Is that how he worded the question?
Was he asking if you can use the same url pattern for two different mappings?

Or.....

Was he asking if you can map to different url patterns to the same servlet name?
swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
I tried this in Tomcat5.028 server I get result
Server doesnot throw any excetion.
But result is unexpected. I hope i got first resource
which has already used this name. But it displays different
Can u answer this how it works?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Read my last question.
We may have had our last two posts cross.

Without knowing exactly what the interviewer asked you, it would be hard to give you an answer.
swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
can you use the same url pattern for two different (resources)mappings?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Personally, I can't see the sense in asking such a question.
Maybe you misunderstood him.

Section 10 of the servlet spec (link in my signature) covers url patterns.

It would make sense for him to ask you about multiple mappings pointing to the same resources. It would also make sense if he asked about the a given request matching two different mappings.
Example
if the request was:
http://www.javaranch.com/myServlets
and you had two mappings that matched this pattern


In this case, section 10 of the servlet spec clearly states which of the two mappings should be used.
Now that I think of it, this must have been what he was asking.
There is no logical reason for the servlet spec to give directions for handling two mappings with identical url-patterns.
[ June 01, 2006: Message edited by: Ben Souther ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Giving same name for URL pattern in web.xml
 
Similar Threads
jsp authentication problem
how to give an aliases to newly added servlet
not able to set the url pattern
Servlet instances
Mapping clash for ServletWrapper