• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

No dynamic data in Velocity template  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo there,

I'm trying to get started with the velocity template engine. I've followed this tutorial:

Link

My problem is, after I deploy my application on Tomcat 8, I miss the dynamic data generated by my servlet in the velocity template. There is only the html stuff I added in the .vm file directly.

---------------------------------

- index.vm: http://pastebin.com/2UbMLCpy

- VelocityServlet: http://pastebin.com/2XuZyKJG

- User Bean: http://pastebin.com/dyRSw3Qz

- web.xml: http://pastebin.com/YxCRrhL2

---------------------------------

With normal JSP/JSTL this would be an easy task, but for a new job beginning in january I have to practise with Velocity. :/

Thanks for your help & greetings,
Jan

 
Master Rancher
Posts: 4076
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the relevant code here?
 
Jan Wieg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my servlet I do:

-----------------------------
request.setAttribute("users", users);
request.setAttribute("foo2", "foobar");
request.setAttribute("foo1", "foobo");

RequestDispatcher requestDispatcher = request.getRequestDispatcher("/index.vm");
requestDispatcher.forward(request, response);

-----------------------------

And in my index.vm I do:

-----------------------------
<html>
<head> <title>Hello Velocity</title> </head>
<body>
<h1>Hello World!</h1>
<br />

$foo1
<br>
$foo2

</body>
</html>

-----------------------------

But after deploying, the HTML page in the browser looks like:

-----------------------------
$foo1
$foo2
-----------------------------

So the html file can't recieve any data from servlet. My guess is, that there is something wrong with my web.xml. In Velocity I have to do the servlet-mappings'n stuff - in JSP/JSTL I do this with the Annotation 'WebServlet()'.

Maybe you could have a look at the web.xml (see my original post above).

Thank you!
 
Dave Tolls
Master Rancher
Posts: 4076
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show the relevant bits of the web.xml here?
The parts where you map the Velocity servlet etc.
I don't go to random links...and in any case, it's better if the information is actually here.
 
Jan Wieg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've already solved it by myself.

I have to extend the Servlet with the VelocityViewServlet like this:

public class VelocityServlet extends VelocityViewServlet

Now it works.

Thank you anyway!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!