velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve O'Hara" <soh...@pivotal-solutions.co.uk>
Subject RE: Probably Spam Newb: SampleServlet Example not working
Date Tue, 02 Aug 2005 12:17:48 GMT
Hi Mike,

The problem is in your Tomcat configuration.  Here's how it works:-

Firstly-
When Tomcat cranks up, it looks in the server.xml file to determine what
servlets/plugins etc to load.
You need to make sure that you have a <context> descriptor in here like the
following for your application;
        <Context path="/CorrMan" docBase="D:\GLA\CorrMan"
         debug="0" reloadable="false"> </Context>
This tells Tomcat that a servlet exists in "D:\GLA\CorrMan" and that
requests that start with /CorrMan should be directed to it e.g.
http://localhost/CorrMan

Secondly-
A servlet directory MUST contain a WEB-INF subdirectory (e.g.
D:/GLA/CorrMan/WEB-INF) within which there MUST be a web.xml file.
The web.xml file tells Tomcat which class to invoke when it recieves a
request destined for your servlet.
Here's a typical one;
<web-app>
    <servlet>
        <servlet-name>CorrManServlet</servlet-name>
        <servlet-class>com.pivotal.CorrManServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CorrManServlet</servlet-name>
        <url-pattern>/main/*</url-pattern>
    </servlet-mapping>
</web-app>
This maps requests like http://localhost/CorrMan/main/blahblahblah to the
class com.pivotal.CorrManServlet

Finally-
You need to make sure that the Tomcat servlet container can find your class.
You do this by either putting it in a jar file within a lib subdirectory of
WEB-INF, a war file in the root of WEB-INF or explicitly within the classes
subdirectory of WEB-INF e.g.
D:\GLA\CorrMan\WEB-INF\classes\com\pivotal\CorrManServlet.class

That's about it - I haven't looked at your example to know the specific
details, but this should be enough for you to work the rest out.

Steve


-----Original Message-----
From:
velocity-user-return-16463-sohara=pivotal-solutions.co.uk@jakarta.apache
.org
[mailto:velocity-user-return-16463-sohara=pivotal-solutions.co.uk@jakart
a.apache.org]On Behalf Of Mike D'Ambrogia
Sent: 01 August 2005 23:41
To: velocity-user@jakarta.apache.org
Subject: Probably Spam Newb: SampleServlet Example not working


All,

New/inexperienced in Tomcat 5.0.28 but getting there slowly, currently
reading the tomcat tutorial.  I've searched the V-U archives on
marc.theaimsgroup.com without luck.  Trying to get the simpleservlet
example up and running without luck.  I've gone overboard with info here
in the hopes that the configuration mistake I'm making will be readily
apparent to someone.

TC located in C:\apache\tomcat\ on Win2kpro system,
JAVA_HOME=j2sdk1.4.2_04 but also have jdk1.5.0_04 on the system too

Per the instructions in
velocity-1.4\examples\servlet_example1\readme.txt I've done the
following:

 - made a new directory structure as follows :

      C:\apache\tomcat\webapps\velexample
      ./velexample/WEB-INF
      ./velexample/WEB-INF/lib
      ./velexample/WEB-INF/classes

 - put the velocity.jar into the velexample/WEB-INF/lib directory (it
came named as velocity-1.4.jar, have not renamed)

 - put the SampleServlet.class into the velexample/WEB-INF/classes
directory

 - put the sample.vm template into the velexample directory.

 - restart tomcat and access the servlet at
http://127.0.0.1:8080/velexample/servlet/SampleServlet

I've done nothing else to TC other than stop/start it.  on restart the
console output shows this:

Aug 1, 2005 3:18:18 PM org.apache.catalina.core.StandardHostDeployer
install
INFO: Installing web application at context path /velexample from URL
file:C:\Apache\Tomcat\webapps\velexample
Aug 1, 2005 3:18:18 PM org.apache.catalina.startup.ContextConfig
applicationConfig
INFO: Missing application web.xml, using defaults only
StandardEngine[Catalina].StandardHost[localhost].StandardContext[/velexa
mple]
Aug 1, 2005 3:18:18 PM org.apache.catalina.core.StandardHost start

after restart I go to the url above and get this:

HTTP Status 404 - /velexample/servlet/SampleServlet
type Status report
message /velexample/servlet/SampleServlet
description The requested resource (/velexample/servlet/SampleServlet)
is not available.

If I go to  http://127.0.0.1:8080/velexample/ I get a dir listing

If I click on the sample.vm file in the listing I get the actual
contents of the .vm file without the velocity substitutions for $name,
$list, etc displayed which is probably correct given that I'm not
running thru the servlet.

Notes towards the bottom of \velocity-1.4\docs\developer-guide.html make
reference to changes that need to be made to the web.xml file, adding:

<servlet>
  <servlet-name>MyServlet</servlet-name>
  <servlet-class>com.foo.bar.MyServlet</servlet-class>
  <init-param>
      <param-name>properties</param-name>
      <param-value>/velocity.properties</param-value>
  </init-param>
</servlet>

Is this chg to web.xml required to run this example code??  Info is abit
thin (for me at least) on what the values for servlet-name and
servlet-class should be, looking for some help with these.  If this chg
is necessary can I add it to a web.xml file in
C:\Apache\Tomcat\webapps\velexample\WEB-INF\web.xml?

All help appreciated, looking fwd to coming up to speed

Mike




---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message