zackhalil
zackhalil

Reputation: 553

Tomcat URL Servlet Mapping

I have a sevelet with mapping like

<servlet-mapping>
      <servlet-name>Inventory</servlet-name>
      <url-pattern>/inventory</url-pattern>
</servlet-mapping>

I would like to create a url mapping to /invlist that goes to /inventory?q=list

Upvotes: 0

Views: 73

Answers (1)

Ken Chan
Ken Chan

Reputation: 90567

<servlet-mapping> only maps a Servlet to a URL but cannot map a URL to URL.

You need to create another Servlet for /invlist and in this Servlet , redirect to /inventory?q=list using HttpServletResponse#sendRedirect

<servlet-mapping>
      <servlet-name>Inventory</servlet-name>
      <url-pattern>/inventory</url-pattern>
</servlet-mapping>

<servlet-mapping>
      <servlet-name>InventoryList</servlet-name>
      <url-pattern>/invlist</url-pattern>
</servlet-mapping>

Then in the InventoryList Servlet :

httpServletResponse.sendRedirect("inventory?q=list")

Upvotes: 1

Related Questions