How can I use a servlet in my grails application?

I need to use some connectors, which are actually servlets. How can I do this in Grails and how about web.xml? How to configure servlet url?

Actually, I have a Spring application, and I'm trying to convert it to a partial Grails application. I have a connection servlet in spring -app that I want to use here, but matching is required to invoke the servlet in the gsp file. How can i do this? I basically need to know where the xml file is in the case of Grails.

+5
source share
3 answers

To get the file web.xml, you can run:

grails install-templates

Then the file can be found in:

<yourapp>/src/templates/war/web.xml

, <servlet> <servlet-mapping>, :

<yourapp>src/java/your/package/structure/WhateverServlet.java

+8

grails, *GrailsPlugin.groovy, . . :

def doWithWebDescriptor = { xml ->
   []
}

:

    def servlets = xml.'servlet'
    servlets[servlets.size() - 1] + {
        servlet {
            'servlet-name'('yourName')
            'servlet-class'('yourpackage.YourClass')
        }
    }

    def mappings = xml.'servlet-mapping'
    mappings[mappings.size() - 1] + {
        'servlet-mapping' {
            'servlet-name'('yourName')
            'url-pattern'('/yourPattern/*')
        }
    }
+3

, . spring URI, , domain.com/abc/def/efg/abc vs grails -, domain.com/controller/view. : URL- URL- Grails GSP

The good news is that you don’t have to deal with XML mapping, grails does it all the same with controllers and views. So you are almost limited to domain.com/YouController/YourView/SomeParamteres ... but if that's all you need, all you have to do is create grails-app / Controller / SomethingController.groovy and you will automatically get domain.com/what

-3
source

All Articles