<strong>Background</strong>
Hello, I'm new to Java EE. I'm following <a href="https://milkedeek.wordpress.com/2012/08/20/groovy-and-tomcat-pt1/" rel="nofollow noreferrer">this tutorial</a> that outlines how to call a groovy class from a java project. Reason for doing this is a lot of pre-existing code I have built is written in groovy, and is fairly extensible for what I would like to do.
<strong>Context</strong>
From a Java and Groovy perspective, the code works. However when firing up the tomcat server and opening
, I am not able to hit the code.
When looking at the
file, I see error:
for
,
, and
.
<strong>Additional Information / Thoughts</strong>
Could this be something to do with my dependencies?
I used
to import
,
,
,
. Are they the wrong ones? Before adding dependencies,
was not able to be found (obviously)
<strong>Expected output</strong>
Open a web browser and the page displays "I'm using java! that's okay.... I was called from groovy, Exciting"
<strong>Actual Output</strong>
I'm using ! That's
<strong>Here's the code:</strong>
index.jsp:
JavaServlet.java
web.xml
main.groovy
Hello, I'm new to Java EE. I'm following <a href="https://milkedeek.wordpress.com/2012/08/20/groovy-and-tomcat-pt1/" rel="nofollow noreferrer">this tutorial</a> that outlines how to call a groovy class from a java project. Reason for doing this is a lot of pre-existing code I have built is written in groovy, and is fairly extensible for what I would like to do.
<strong>Context</strong>
From a Java and Groovy perspective, the code works. However when firing up the tomcat server and opening
Code:
index.jsp
When looking at the
Code:
index.jsp
Code:
cannot resolve variable
Code:
language
Code:
sentiment
Code:
message
<strong>Additional Information / Thoughts</strong>
Could this be something to do with my dependencies?
I used
Code:
maven
Code:
ant:ant-antlr:1.6.5
Code:
asm:asm-all:3.3.1
Code:
jstl:jstl:1.2
Code:
org.codehaus.groovy:groovy-all:2.2.1
Code:
Java.sun.com/jsp/jstl/core
<strong>Expected output</strong>
Open a web browser and the page displays "I'm using java! that's okay.... I was called from groovy, Exciting"
<strong>Actual Output</strong>
I'm using ! That's
<strong>Here's the code:</strong>
index.jsp:
Code:
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>Test Sandbox</title>
</head>
<body>
<p>I'm using <c:out value="${language}" />! That's <c:out value="${sentiment}" /></p>
<p><c:out value="${message}" /></p>
</body>
</html>
JavaServlet.java
Code:
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class JavaServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getSession().setAttribute("language", "java");
req.getSession().setAttribute("sentiment", "ok...");
resp.sendRedirect("index.jsp");
req.getSession().setAttribute("message", main.message());
}
}
web.xml
Code:
<?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>JavaServlet</servlet-name>
<servlet-class>JavaServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>JavaServlet</servlet-name>
<url-pattern>/javacallinggroovy</url-pattern>
</servlet-mapping>
</web-app>
main.groovy
Code:
class main {
static def message() {
"I was called from Groovy. Exciting, isn't it?"
}
}