Can't get my servlets to run and PHP on Tomcat

I downloaded and installed Apache Tomcat Server 5.0.28 and all is working fine, the JSP and servlet examples that came with the server work fine as well. I've writen a small example servlet and I can't the the damn thing to run, I don't know where to place it and what must be changed in which .xml file. I did follow all the documentation on how to do it but I guess that was writen by a non-user-friendly person because I can't follow most of it...

I´ve also heard that Tomcat can do PHP ( http://wiki.apache.org/jakarta-tomcat/UsingPhp ) but those it seems to me those instructions are for Linux and I can't really figure out how to get it done in Windows...

I hope to get some input and a nice example would be much appreciated...

Thanx

;)
LVL 9
stefanaichholzerAsked:
Who is Participating?
 
kiranhkCommented:
0
 
kiranhkCommented:
you need to place your compiled java class file in the
c:\jakarta-tomcat-5.5.2\webapps\servlets-examples\WEB-INF\classes  folder (assuming you have ur tomcat installed in c drive) Then u need to change the web.xml located in the WEB-INF folder in the same path just above the classes folder. then u need to restart the tomcat and access by the URL. the above link which i have given will give u a fair idea
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
petmagdyCommented:
dear sir their are two approches to deploy ur servlets, either ur create ur own web module and deploy it or add ur servlet to an existing deployed module over tomcat

if u will do this as a separate web module do the following assuming that ur servlet is (mypackage.myservlet),

1- create a web.xml file contains the following:

<?xml version = '1.0' encoding = 'windows-1252'?>
<!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>
  <description>Empty web.xml file for Web Application</description>
  <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>mypackage.myservlet</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>myservlet</servlet-name>
      <url-pattern>/myservlet</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

3- compile ur servlet
2- using a jar or even zip utitly create a directory tree of ur module as following:

root
|----->WEB-INF/web.xml
|----->WEB-INF/classes/mypackage/myservlet.class

and name it for example myweb.war

4- using tomcat admin deploy ur war and specify a context root like myweb

5 - call http://host:port/myweb/myservlet


0
 
petmagdyCommented:
in case u want to deploy on an existing Web module do this:

1- compile ur servlet and put it as following
{tomcat-home}\webapps\servlets-examples\WEB-INF\classes\ mypackage/myservlet.class
 
open web.xml in {tomcat-home}\webapps\servlets-examples\WEB-INF

and add this section:

  <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>mypackage.myservlet</servlet-class>
  </servlet>
  <servlet-mapping>
     <servlet-name>myservlet</servlet-name>
     <url-pattern>/myservlet</url-pattern>
  </servlet-mapping>

3- restart tomcat and try http://host:port/{examples-context-root}/myservlet

good luck
0
 
stefanaichholzerAuthor Commented:
petmagdy,

I´ll try your suggestions, but tell me one more thing, what if I don't want to place my .class file in the /servlet-examples/ folder in Tomcat?, can't I just place my .class files in the ROOT folder or create a new folder for my servlets??

Thank you for your time, much appreciated...

;)
0
 
petmagdyCommented:
No because assembling applications in J2EE is due to specific standards, but if u r going to create ur own web module tomcat will deploy ur classes in a separate directory, please also that if u packaged ur code (mycode.jar) into a jar file u can place it into a specific place for jar libraries that is:

{tomcat-home}\webapps\servlets-examples\WEB-INF\lib\mycode.jar

 that will do it also
0
 
stefanaichholzerAuthor Commented:
petmagdy,

I didn't quite follow your last post but I'll try to get it all done in the /servlet-examples/ folder.

Now my point is; the name says it´s an example folder ( /servlet-examples/ ), so there must be a way to create a folder, say /servlets/ and have all the servlets in there, right? and just configure Tomcat to run the servlets from that folder...

I hate it when things are so complicated as this...

Could you answer the second part of my question about Tomcat doing PHP?

Thanx

;)
0
 
stefanaichholzerAuthor Commented:
petmagdy,

This is what I mean:

In its default configuration, Tomcat expects you to place compiled Servlets in the webapps\ROOT\WEB-INF\classes subdirectory of the Tomcat installation directory to deploy them. Place your compiled MyServlet.class file in that directory, then (assuming Tomcat is running on your local computer) load http://localhost:8080/servlet/MyServlet.

There I don't need to place my .class files into the /servlet-examples/ folder, just what I want, still I don't know if I will get the baby to run...

Read on: http://www.sitepoint.com/article/java-servlets-1/4

kiranhk,

Thanx for the valuable links...

;)
0
 
kiranhkCommented:
yes, you can place your class file in webapps\ROOT\WEB-INF\classes . since ROOT is also a web application.
If you have gone thro' the article fully they also specify why u need to add an entry in the web.xml.
If you dont add an entry in the web.xml you will have to access ur servlet using the class name of ur servlet. pl go thro' the article fully and u will be able to get ur baby to run..... and  i mean run real fast........ :)
0
 
stefanaichholzerAuthor Commented:
kiranhk,

I went through the article and the thing is now running, was actually pretty simple once I knew what to do...

Thank you for your time, you have been so much more the kind...

:)
0
 
kiranhkCommented:
you r always Welcome :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.