• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Velocity servlet

 
shubhra mathur
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have created one velocity servlet and velocity template which is called by servlet. Velocity.properties file is created where i am giving the path of template .
When i am calling the sevlet in web browser it is showing servlet not found exception though i have given the path of servlet in web.xml.
Please help me.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Which URL are you using to access the servlet, and what do the servlet declaration and mapping from web.xml look like? TellTheDetails
 
shubhra mathur
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In url i am giving localhost:8080/servletname.
My web.xml--
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>Hello</servlet-class>
<init-param>
<param-name>properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/Hello</url-pattern>
</servlet-mapping>

</web-app>
my Servlet---
import org.apache.velocity.Template;
import org.apache.velocity.servlet.VelocityServlet;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.context.Context;
import javax.servlet.http.*;

public class Hello extends VelocityServlet {

private static final long serialVersionUID = 1L;

public Template handleRequest( HttpServletRequest request,
HttpServletResponse response,
Context context ) {

Template template = null;

try {
context.put("name", "Velocity Test");
template = Velocity.getTemplate("/hello.vm");
} catch( Exception e ) {
System.err.println("Exception caught: " + e.getMessage());
}

return template;
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic