• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

two servlets with same url pattern

 
Sandeep Bhandari
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a query that if two servlets match a url-pattern then which servlet will be invoked.

I tried it and got an error "HTTP Status 405 - HTTP method POST is not supported by this URL"

May be I had some other problem. Is that the expected behaviour??
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I doubt that the two are related. The servlet specification probably mentions which mapping should prevail if more than one matches an URL.

The error means that the servlet does not have a proper doPost method.
 
Garlapati Ravi
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's nothing to do with the error that you got, you might have missed doPost() method in your servlet.

always it calls the second <url-patten>, i tried with the below web.xml




[ April 23, 2008: Message edited by: Garla Ravi ]
[ April 23, 2008: Message edited by: Garla Ravi ]
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
always it calls the second <url-patten>

Is that how your particular servlet container works, or what the servlet specification states?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do not trust what your container does. The specification does not seem to tell which servlet will be taken first (or I'm missing it). It depends on the way the container stores the servlets.
----------------------------
SRV.11.1 Use of URL Paths

The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters. The URL path mapping rules below are used in order. The first successful match is used with no further matches attempted:

1. The container will try to find an exact match of the path of the request to the path of the servlet. A successful match selects the servlet.
----------------------------
The first successful match. But in what order ?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first successful match. But in what order ?

I think that means "the order in which they are listed in the web.xml file".
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But does the container store servlets in the order they are declared in web.xml ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic