Search code examples
model-view-controllerservletsoperationsmappings

How can one identify the operation to perform in a servlet?


I am trying to follow this example but I can't understand this part:
Imagine also that the servlet's context path is myServer/myApp/servlets. The servlet container would direct a request with URL myServer/myApp/createUser.do myServlet to myServlet, because the request URL matches the pattern *.do. Servlet myServlet can extract the requested operation's name from the request URL.
I can't understand the request, shouldn't it be myServer/myApp/myServlet/createUser.do? And how can one create such a request? Can I just put myServlet/createUser.do in the action of a form?
Thank you for your time.
Iulia


Solution

  • No, you create a mapping to your servlet for myapp. The servlet name itself usually never shows in the request URL. So every request that goes to myapp will be redirected to your servlet if it matches. That means that your mapping

    http://myserver/myapp/*.do

    redirects every request with a .do to your servlet. Now the servlet has to deal with the request URL (e.g. render the view for createUser)