Take the 2-minute tour ×

I've been tasked with creating a JSP tag that will allow developers to pass a URI to an xml document, and have an object returned that can be navigated using EL.

I have been using groovy and grails quite a bit so I thought of trying something like

rval =  new XmlSlurper().parseText(myXml);

and throwing that into the request so that back in the JSP they might do something like:

<mytag var="var"/>

but that approach doesn't work.

Does anyone have any suggestions?

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Gizmo is correct that the problem is that JSPs assume everything is Java, but I doubt that switching to GSP is a practical answer. To work around this, you need to know how Groovy code gets translated to Java. The Groovy code:


Is roughly equivalent to this Java:


It may also be necessary to cast each result to a GPathResult, e.g.,


Java sucks, huh?

share|improve this answer
add comment

It does not work because the JSP is compiled using the java compiler, not the groovy compiler. You should use a GSP instead, otherwise you won't be able to use the groovy mechanism that internally call methods when you use a GPath expression.

share|improve this answer
add comment

Your Answer


