| Refresh | Home EGTry.com

tomcat servlet url mapping in web.xml


  <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
  </servlet-mapping>


url mapping examples

url getContextPath() getServletPath() getRequestPath() getQueryString()
http://localhost:8080/dynamicweb111/hello /dynamicweb111 /hello /dynamicweb111/hello null
http://localhost:8080/dynamicweb111/hello?name=John&age=35 /dynamicweb111 /hello /dynamicweb111/hello name=John&age=35
http://localhost:8080/dynamicweb111/hello.do not match
http://localhost:8080/dynamicweb111/hello/world not match

extension mapping

  <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>*.xml</url-pattern>
  </servlet-mapping>


extension mapping examples

url getContextPath() getServletPath() getRequestPath() getQueryString()
http://localhost:8080/dynamicweb111/hello.xml /dynamicweb111 /hello.xml /dynamicweb111/hello.xml null
http://localhost:8080/dynamicweb111/hello/world.xml /dynamicweb111 /hello/world.xml /dynamicweb111/hello/world.xml null
http://localhost:8080/dynamicweb111/hello.XML NOT MATCH case sensitive
http://localhost:8080/dynamicweb111/hello NOT MATCH

match all

  <servlet-mapping match all>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>


match all mapping examples

url getContextPath() getServletPath() getRequestPath() getQueryString()
http://localhost:8080/dynamicweb111/ /dynamicweb111 / /dynamicweb111/ null
http://localhost:8080/dynamicweb111/hello /dynamicweb111 /hello /dynamicweb111/hello null
http://localhost:8080/dynamicweb111/hello.txt /dynamicweb111 /hello.txt /dynamicweb111/hello.txt null
http://localhost:8080/dynamicweb111/hello/world.xml?name=Jsessica&flag=true /dynamicweb111 /hello/world.xml /dynamicweb111/hello/world.xml name=Jsessica&flag=true

path prefix mapping

  <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello/*</url-pattern>
  </servlet-mapping>


path prefix mapping examples

url getContextPath() getServletPath() getRequestPath() getQueryString()
http://localhost:8080/dynamicweb111/ /dynamicweb111 / /dynamicweb111/ null
http://localhost:8080/dynamicweb111/hello /dynamicweb111 /hello /dynamicweb111/hello null
http://localhost:8080/dynamicweb111/hello/world/index.html?id=2&name=lee /dynamicweb111 /hello /dynamicweb111/hello/world/index.html id=2&name=lee
http://localhost:8080/dynamicweb111/hell NOT MATCH
http://localhost:8080/dynamicweb111/world/hello NOT MATCH