• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HF S&J Error page:587-588

 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While mapping URLs the third URL in the "Be The Container".

It says http://localhost:8080/MapTest/fooStuff/bar/blue.do should map to

DeployTestTwo servlet but in the Answers section on page 588

It says "DeployTestThree". Although longest path is /fooStuff/bar so it

should be DeployTestTwo as corerct answer and I also confirmed it from Tomcat

Server after matching this URL pattern.

Please correct me if I am wrong.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... I'll take a look at that, but I think our answers are correct, so I'm not sure what Tomcat is doing. Here's the reason:

The servlet mapping for DeployTestTwo is a URL pattern /fooStuff/bar, which is an exact match.

So the /fooStuff/bar/blue.do does not match that URL pattern exactly. If DeployTestTwo was mapped to /fooStuff/bar/*, then you are correct, and /fooStuff/bar/blue.do would have been the closest match. But since /fooStuff/bar is an *exact match* URL pattern, the /fooStuff/bar/blue.do matched to the URL pattern /fooStuff/*

Does that make sense? So while it is true that the longest match will win, this only works when you are not talking about an *exact* match. In an exact match URL pattern, like /fooStuff/bar, only an exact match will work.

Hmmmm... can you check this again in Tomcat? I'm going to do the same...

thanks,
Kathy
 
Roger Yates
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bahadar/Kathy,

I've tried this out on Tomcat 5.0.28 on XP, and my results agree with Kathy & HFS. It maps to DeployTestThree.

I also tried putting in a mapping to /fooStuff/bar/* as well as /fooStuff/bar, which made the request map to /fooStuff/bar/* instead as Kathy suggested. Perhaps you inadvertently put this in your DD?
 
Bahadar Khan
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy/Rogers

Probably I have made some mistake, but as that code is not infront of me where I tested before. But now here in my home, I have tested this on three servers, Tomcat 4.0, Tomcat 5.0 and Weblogic 8.1, and it is following the *exact* URL rules. So answer is correct. But I would like to finish this thread until tomorrow morning where I would be able to see the previous code that made me to write this error. I think the server there was something 4.x.

Thanks to both of you for help, I will write more on it tomorrow after looking at other code.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This stuff is always tricky to test, because you often won't get any errors about what is in your DD, and because different versions of Containers do not always follow the spec *exactly*. What is in the book has all been tested on Tomcat 5, but even slight variations in versions of Tomcat can sometimes show different results. Ahhh... for the good old days when all you had to do was run javac and java to test everything

cheers,
Kathy
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy,


you often won't get any errors about what is in your DD, and because different versions of Containers do not always follow the spec *exactly*.

In such sense, what is the best (or better) practices for us to discover such problems?

Are there any convenient ways?

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic