I need to use some connectors which are actually servlets. How can I do this in Grails and what about the web.xml? How do I configure the url of the servlet?
I actually have a Spring application here and I am trying to convert it into a partial Grails app. I have a connector servlet in the spring-app, which I wish to use here but the mapping is a must to call the servlet in the gsp file. How can I do this? I basically need to know where the xml file is in case of Grails.
To get the web.xml
file, you can run:
grails install-templates
Then, the file can be found in:
<yourapp>/src/templates/war/web.xml
Edit this as usual to add <servlet>
and <servlet-mapping>
sections, then put your servlet code in:
<yourapp>src/java/your/package/structure/WhateverServlet.java
and you should be good to go
If you are within a grails-plugin, then you have a defined place within your *GrailsPlugin.groovy
, where to do such things. E.g. Look at the auto generated closure:
def doWithWebDescriptor = { xml ->
[]
}
In here you can add your custom servlet configurations:
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/*')
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With