Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-22
14
Medium Priority
?
343 Views
Last Modified: 2013-11-24
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

;)
0
Comment
Question by:stefanaichholzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 3
14 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12384660
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12384681
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12384683
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:petmagdy
ID: 12384729
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
 
LVL 9

Author Comment

by:stefanaichholzer
ID: 12384874
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12384910
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
 
LVL 9

Author Comment

by:stefanaichholzer
ID: 12384972
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
 
LVL 8

Accepted Solution

by:
kiranhk earned 1500 total points
ID: 12385007
0
 
LVL 8

Expert Comment

by:kiranhk
ID: 12385032
0
 
LVL 9

Author Comment

by:stefanaichholzer
ID: 12385232
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
 
LVL 8

Expert Comment

by:kiranhk
ID: 12385411
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
 
LVL 9

Author Comment

by:stefanaichholzer
ID: 12388990
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
 
LVL 8

Expert Comment

by:kiranhk
ID: 12400528
you r always Welcome :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question