• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mapping the URL pattern with the action in form

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i confused over mapping the URL in the XML with the one i given in the action attribute of FORM tag.

can any one explain me over that
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assume this in web.xml

<servlet>
<servlet-name> Login </servlet-name>
<servlet-class> LoginServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> Login </servlet-name>
<url-pattern> /login </url-pattern>
</servlet-mapping>

servlet-mapping : You have a servlet-mapping corresponding to every URL pattern that you want your web application to support. The value of the url-pattern tag is the form action. For instance, if your application context is, say, 'shopping', then the form action will be "/shopping/login"

servlet : You have a servlet tag for every servlet of your application.

The container looks for the request URI. In this case, it is "/login" after the context has been stripped out. It takes the servlet name for this URI as "Login" (from <servlet-name> in <servlet-mapping> , goes to all <servlet> tags and looks out for one with this name. It takes the class "LoginServlet" from the <servlet-class> tag of the matching <servlet> tag and executes the request method in it (doGet, doPost ...)
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would add that it's a bad idea to hardcode the context name your HTML.
"/shopping/login".
Rather, use the request.getContextPath() property to read it dynamically.
This way if you ever have to change the context name, or a second instance (shopping_test, shopping_dev) etc, you won't have to work though all of your code to update it.
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i dynamically get the context [request.getContextPath()] in a HTML? If it is a JSP page, yes, i agree.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic