At one point, there was one noticeable problem, which prevented me from completely replacing PHP with Groovy for the web without using the relatively heavyweight Grails MVC framework.
This applies to * .gsp pages (Groovy Server Pages), which are html-pages with inserts like <% ...%> with arbitrary code in Groovy or Java, or in the original language: "
GSP means GroovyServer Pages, which is similar to JSP ( JavaServer Pages). "
')
Exactly the same functionality in PHP is implemented with <? ...?> Inserts (and for PHP the presence of such a block is mandatory, even if it implements classes or business logic; if after such a block there is usually an invisible space or a line break, then it will fall into conclusion that can lead to problems).
The site says: "
GSP are not maintained as a standalone module. But it has been forked and reintegrated in Grails ." But, nevertheless, like the servlet grubs, gsp pages work without Grails, it is enough just to connect the gruv to the application.
The problem was that in these gsp-pages the Russian text was turned into “krakozyabry”. This was not observed in the servlet grunt, both in the “real” and script types.
Using the scientific method, it turned out that if the gsp source is converted to the default encoding on the system (for example, cp1251 for Windows), then the problem is solved (moreover, the page is displayed in UTF-8).
And this is a clear tip: go to the source of the servlet groovy.servlet.TemplateServlet.java, which is responsible for parsing such pages, and find the line there:
private static final String GROOVY_SOURCE_ENCODING = "groovy.source.encoding";
It also shows how this parameter affects the creation of a Reader instance.
We register the parameter to the servlet with the value “UTF-8” in the web.xml of the application, and voila, the problem is solved.
The full text of the web.xml application, in which all arbitrary * .groovy and * .gsp files will be compiled into servlets and correctly output Cyrillic:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>GroovyServlet</servlet-name> <servlet-class>groovy.servlet.GroovyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>GroovyServlet</servlet-name> <url-pattern>*.groovy</url-pattern> <url-pattern>*.grv</url-pattern> </servlet-mapping> <servlet> <servlet-name>GSP</servlet-name> <servlet-class>groovy.servlet.TemplateServlet</servlet-class> <init-param> <param-name>groovy.source.encoding</param-name> <param-value>UTF-8</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>GSP</servlet-name> <url-pattern>*.gsp</url-pattern> </servlet-mapping> </web-app>
It also shows how a long .groovy extension that will “glow” in url addresses can be replaced with an arbitrary short, for example .grv (or .php - just 4 fun).
Now you can quickly and easily write sites, web applications, frameworks on Groovy, for which you will need only installed Java and Tomcat on the server.