Types of URL pattern supported by Tomcat


This tutorial will walk through about how many types of URL pattern supported by Tomcat server or container. Tomcat is most popular and widely used servlet container by the Java developer. Tomcat container will support 3 type of URL pattern.

Character Sequence Match

In this type of URL pattern matching, the request will match the complete character of the action.

<servlet>
    <servlet-name>register</servlet-name>  
	<servlet-class>org.websparrow.RegisterAction</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>register</servlet-name>
    <url-pattern>/registerEmployee</url-pattern>
</servlet-mapping>

In this case, only a request from registerEmployee action will be handled by RegisterAction servlet but if RegisterAction handles multiple registrations, you need to map all them and it will increase the size of the deployment descriptor and complexity.

Expression or Directory Match

Expression or directory math type URL pattern matches the directory and expression.

<servlet>
	<servlet-name>register</servlet-name>  
	<servlet-class>org.websparrow.RegisterAction</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>register</servlet-name>
    <url-pattern>/emp/*</url-pattern>
</servlet-mapping>

In this case, RegisterAction servlet handles all request from emp directory. This type of URL pattern is suitable for a single MVC framework application.

Extension Match

Extention match URL pattern is recommended by the industry. It matches the extension of the URL.

<servlet>
    <servlet-name>register</servlet-name>  
	<servlet-class>org.websparrow.RegisterAction</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>register</servlet-name>
    <url-pattern>/emp/*.action</url-pattern>
</servlet-mapping>

In this case, RegisterAction servlet will handle all those URLs which have the action extension from emp directory. You can integrate the multiple MVC framework together.


Similar Posts

About the Author

Atul Rai
I love sharing my experiments and ideas with everyone by writing articles on the latest technological trends. Read all published posts by Atul Rai.