9-Sep-04 (Created: 9-Sep-04) | More in 'Howto'

How to use shorter urls when developing with Aspire

By slightly altering the the web-inf\web.xml you will be able to do this


http://host/your-app/display?url=Pag1URL&arg1=10
http://host/your-app/update?request_name=StateChangeRequest&arg1=10

Previously you would have needed to do


http://host/your-app/servlet/DisplayServlet?url=Pag1URL&arg1=10
http://host/your-app/servlet/UpdateServlet?request_name=StateChangeRequest&arg1=10

Add the following servlet mappings to web.xml


    <servlet-mapping>
        <servlet-name>DisplayServlet</servlet-name>
        <url-pattern>/display</url-pattern>
    </servlet-mapping>
	
    <servlet-mapping>
        <servlet-name>UpdateServlet</servlet-name>
        <url-pattern>/update</url-pattern>
    </servlet-mapping>
	
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>

The parent xml node to add them to is


<web-app>

Another way to look at this is


<web-app>
    <servlet-mapping>
        <servlet-name>DisplayServlet</servlet-name>
        <url-pattern>/display</url-pattern>
    </servlet-mapping>
	
    <servlet-mapping>
        <servlet-name>UpdateServlet</servlet-name>
        <url-pattern>/update</url-pattern>
    </servlet-mapping>
	
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
</web-app>

Appendix-1: The complete web.xml file


<web-app>
<!-- ******************************************************************** 
 * Define Aspire servlets
 *		PageDispatcherServlet 	for display screens
 *		RequestExecutorServlet 	for update/insert/delete etc screens
 *		VerifyBaseServlet		for testing aspire
 ************************************************************************ 
 -->

<servlet>
        <servlet-name>
            AppInitServlet
        </servlet-name>
        <servlet-class>
            com.ai.servlets.AppInitServlet1
        </servlet-class>
        <init-param>
            <param-name>AppConfigFilename</param-name>
            <param-value>aspire.properties</param-value>
        </init-param>
	<load-on-startup>
		1
	</load-on-startup>
    </servlet>

<servlet>
        <servlet-name>
            DisplayServlet
        </servlet-name>
        <servlet-class>
            com.ai.servlets.PageDispatcherServlet
        </servlet-class>
    </servlet>

<servlet>
        <servlet-name>
            UpdateServlet
        </servlet-name>
        <servlet-class>
            com.ai.servlets.RequestExecutorServletT1
        </servlet-class>
    </servlet>

<servlet>
        <servlet-name>
            TestServlet
        </servlet-name>
        <servlet-class>
            com.ai.servlets.VerifyBaseServlet
        </servlet-class>
    </servlet>

<!-- ******************************************************************** 
 * Define Aspire servlet mappings, one for each of the following
 *		PageDispatcherServlet 	
 *		RequestExecutorServlet 	
 *		VerifyBaseServlet		
 ************************************************************************ 
 -->
    <servlet-mapping>
        <servlet-name>
            TestServlet
        </servlet-name>
        <url-pattern>
            /servlets/TestServlet
        </url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>
            TestServlet
        </servlet-name>
        <url-pattern>
            /test
        </url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>
            DisplayServlet
        </servlet-name>
        <url-pattern>
            /servlets/DisplayServlet
        </url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>
            DisplayServlet
        </servlet-name>
        <url-pattern>
            /display
        </url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>
            UpdateServlet
        </servlet-name>
        <url-pattern>
            /servlets/UpdateServlet
        </url-pattern>
    </servlet-mapping>
    
    <servlet-mapping>
        <servlet-name>
            UpdateServlet
        </servlet-name>
        <url-pattern>
            /update
        </url-pattern>
    </servlet-mapping>

<!-- ******************************************************************** 
 * Singular servlet
 ************************************************************************ 
 -->
    <servlet-mapping>
        <servlet-name>
            TestServlet
        </servlet-name>
        <url-pattern>
            /servlet/TestServlet
        </url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>
            DisplayServlet
        </servlet-name>
        <url-pattern>
            /servlet/DisplayServlet
        </url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>
            UpdateServlet
        </servlet-name>
        <url-pattern>
            /servlet/UpdateServlet
        </url-pattern>
    </servlet-mapping>


<!-- ******************************************************************** 
 * End of Aspire Servlet definitions
 ************************************************************************ 
 -->
</web-app>