aspose file tools*
The moose likes Servlets and the fly likes question on servlet-mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "question on servlet-mapping" Watch "question on servlet-mapping" New topic
Author

question on servlet-mapping

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
One of my friends asked me ... For Servlets in < servlet-mapping > Whats the difference between ... "/mywebsite/myservlet/" and "/mywebsite/myservlet" ??

that is


and


Is there any or no difference ?
[ May 28, 2008: Message edited by: Bear Bibeault ]

lavnish.blogspot.com
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
Throw a Hello World together and see what it does...
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
am using jdev11g .. embedded oc4j


and second servlet is


web xml is



on accessing the URL
http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet/
I get http 404 .. not servlet 2
and using
http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet
I get servlet 1

dont understand how & why ??
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
I threw your code (adjusting for my environment) into MyEclipse and was able to get both servlets. I think it may have something to do with your environment. My code is below.

Servlet1



Servlet2


web.xml
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
to get the second servlet ... i.e.
http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet/
I had to modify my web.xml ( embedded oc4j ) to

so the ques modifies to ...


Is the output of above mapping dependent on container used ?? If so why ?? doesnt the servlet spec defines container behavior for above case

BTW ,,, my servlet is according to Servlet 2.5 Specification
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
What Server do you use? I am using Tomcat for MyEclipse and I didn't have to put the * after the "myservlet/"

I set up another project using Java 5 EE and ran the same files and still got both servlets, without adding the "*" again.

As for Dependencies on containers, I don't have an absolute yes or no. But judging by what I was able to run, and what you were not able to run based on the same mapping, I would say yes.

Hope this helps

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
looks like an interesting finding
I am using embedded oc4j11g

Talking of dependency on containers ... Let me put this in another way ...
We know that .. the Requested URI is made up of ... the context path, servlet path, and path info.
And The Servlet Spec clearly (guess so) defines the algorithm for that
so... the following should result in same for all containers ...

and

and


May be we should try on more containers ... or other friends can help us do that .. post the results in this thread ..
what say ??
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
Nickolas ,,, can you pls try

< servlet-mapping >
< servlet-name >ServletOne< / servlet-name >
< url-pattern >/mywebsite/myservlet< / url-pattern >
< / servlet-mapping >


< servlet-mapping >
< servlet-name >ServletTwo< / servlet-name >
< url-pattern >/mywebsite/myservlet/< / url-pattern >
< / servlet-mapping >


< servlet-mapping >
< servlet-name >ServletThree< / servlet-name >
< url-pattern >/mywebsite/myservlet/*< / url-pattern >
< / servlet-mapping >

ans see what happens for
http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet/
will it show "Servlet two" or "servlet three"
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98
I created a third servlet and a third servlet mapping


When I map to servlet 3 with /mywebsite/myservlet/* I get servlet three

So with the following maps




I return servlets one, two, and three, respectively.

What do you return?

[ May 28, 2008: Message edited by: Nickolas Case ]
[ May 28, 2008: Message edited by: Nickolas Case ]
lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
my question was ...


If you keep web.xml as above then for the url http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet/
you can get either servlet2 or servlet3 ... which one did you get ?

see there are only two ways to access from browser .. so there can only be two outputs
(i) http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet/
and
(ii) http://127.0.0.1:8988/DataStructure-Datastructure-context-root/mywebsite/myservlet
(ii) will give servlet1 for sure
(i) will give either servelt2 or servlet3 in your case .. which one is it ?

so when you say ...
"I return servlets one, two, and three, respectively."
i didnt quite understand that ...

In my case if i keep my web.xml as above (i) gives servlet3 (ii) gives servlet1 and am unable to acess servlet2 ....

pls let me know if i need to clarify more ... ( i will be able to ans after 12 hrs now )
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61043
    
  66

Originally posted by lavnish lalchandani:
pls let me know if i need to clarify more ... ( i will be able to ans after 12 hrs now )

Please use real words when posting to the forums. Abbreviations such as "pls" in place of "please" and "ans" instead of "answer" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nickolas Case
Ranch Hand

Joined: Apr 26, 2008
Posts: 98


returns Servlet1



Returns servlet2



Returns servlet3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question on servlet-mapping