Multiple mapping for a Servlet

Multiple mapping for a Servlet

Postby SHilpy » Thu Feb 07, 2013 9:08 pm

What is the need to have multiple mapping for the same servlet?
Posts: 6
Joined: Thu Jan 31, 2013 2:34 am

Re: Multiple mapping for a Servlet

Postby Kishan » Fri Feb 08, 2013 3:27 pm

Yes, you can define multiple servlet-mappings and url patterns for one servlet. It gives flexibility to invoke servlet with different url-patterns.

Example: If you have ItemServlet view item. Lets think seller can view item by calling ItemServlet, buyer can view item by calling ItemServlet. But I would like to access the servlet with different path info as below:

http://localhost:8080/ecommerce/buyeritem --- for buyer flow
http://localhost:8080/ecommerce/selleritem --- for seller flow

In the servlet processing logic might be different dependes what who is calling servlet i.e. buyer or seller. This information can be identified by calling request.getPathInfo() hence different logic executes who is invoking the servlet.

Not only this you can handle different filtering/authorization by having different mappings for the servlet.
Posts: 191
Joined: Tue Jan 29, 2013 4:21 am

Return to Servlets

Who is online

Users browsing this forum: No registered users and 1 guest