Reputation: 105
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.
Upvotes: 5
Views: 5579
Reputation: 8099
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/*')
}
}
Upvotes: 3
Reputation: 171194
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
Upvotes: 8
Reputation: 4637
good news and bad news, and I myself have asked this question here before. With spring application you can have multiple level of URI such as domain.com/abc/def/efg/abc vs grails has a lot of issue with anything beyond domain.com/controller/view. here is a link to my original question: Grails URL mapping cause error on GSP
The good news is, you don't need to deal with XML mapping, grails does it seemlessly by controllers and views. So you are almost limited to domain.com/YouController/YourView/SomeParamteres... but if thats all you'll need, all u have to do is create grails-app/Controller/SomethingController.groovy and you automatically have domain.com/Something
Upvotes: -3