• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question on servlet-mapping

 
lavnish lalchandani
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nickolas Case
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throw a Hello World together and see what it does...
 
lavnish lalchandani
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65124
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nickolas Case
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


returns Servlet1



Returns servlet2



Returns servlet3
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic