views:

449

answers:

1

How can you have a grails application as well as other servlets defined in your web.xml?

I want to have it so that some url patterns are handled by a servlet while all others are handled by Sitemesh/grails.

The default configuration of web.xml generated by grails is:

<filter-mapping>
    <filter-name>charEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>grailsWebRequest</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>
<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>urlMapping</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
</filter-mapping>

<servlet>
    <servlet-name>grails</servlet-name>
    <servlet-class>org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

I then added the configuration to web.xml for my 2nd servlet:

<servlet>
    <servlet-name>Tracepoints</servlet-name>
    <servlet-class>com.mydomain.Tracepoints</servlet-class>
    <init-param>
        <param-name>hostName</param-name>
        <param-value>http://www.mydomain.com/&lt;/param-value&gt;
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Tracepoints</servlet-name>
    <url-pattern>*.tpoints</url-pattern>
</servlet-mapping>

But the above doesn't allow me to access my non grails servlet (with the url: domain.com/hello.tpoints) and trying it gets me a 404. I do know that the servlet's class files are deployed with the war because they exist in WEB-INF/classes directory.

A: 

You need to give the Grails servlet a more specific url-pattern in the mapping, e.g. /grails/* or *.grails or so (you're free to choose), so that only the URL's matching those patterns invokes the Grails servlet.

BalusC