Difficulties with setting up Apache tomcat: 'Need a little help.
Joined: Jul 05, 2002
I would appreciate a little help from all the gurus out there.....
Tomcat refuses to bring up my servlet. I know I've done something wrong somewhere but can't figure out where.
Now let me confess all my wrong deeds:
I'm trying to run servlets (and JSPs) by installing tomcat on j2sdk1.4.0 (and not using J2EE sdk). I have apache Tomcat 4.1.18 installed. I set the JAVA_HOME environment variable to the directory where the J2 SDK is installed on c: (c:\j2sdk1.4.0) I also have APACHE_HOME set to the location of the tomcat installation. But then, while troubleshooting, I also added CATALINA_HOME and made it point to the same location. (My thinking is this wasn't nessesary, but it wouldn't hurt. Was I right?) I have included all the environment variables below in case it would help....
In the webapps directory which resides in the tomcat installation directory, I have my directory named gsmsecurity, which contains a WEB-INF subdirectory. This WEB_INF subdirectory now contains to other subdirectories: lib and classes. My servlet resides inside the classes folder. Now the examples folder that comes with tomcat is on the same level with my gsmsecurity folder.
Richard, I've put the class in a package and included the <servlet-mapping>, like you and Nidhi said I should.
And William, I read
The Long and Sordid Tale of the Invoker Servlet
you linked me to and I got the message. I think I've got it now, only that the page that comes up is blank. First, I did as the FAQ page said at the begining of the page:
In the file conf/web.xml find a section of text that looks like this:
<!-- The mapping for the invoker servlet --> <!-- <servlet-mapping> <servlet-name>invoker</servlet-name> <url-pattern>/servlet/*</url-pattern> </servlet-mapping> --> [/code]
You need to uncomment the servlet-mapping and then restart Tomcat. Your application should work now....
I uncommented these lines. I did this just to see the application work, at least. But knew something was wrong when instead of displaying a webpage, I got a text file downloaded. Then saw it was in the part where the servlet sends the header [code] theResponse.setContentType("text.html"); [/code] . I fixed that to read [code] theResponse.setContentType("text/html"); [/code]. Then I put the servlet in a package named mypackage ( I always prefer to keep things simple at first. The package structure could get deeper later), and I added the <servlet-mapping> tag. But all I get now is a blank page. What am I doing wrong?
In a bid to solve this, I included my classes directory in the classpath. Still didn't work. I then chaged the way output is sent to the browser in the servlet, like this [code] ServletOutputStream out = theResponse.getOutputStream(); out.println("<HTML>"); [/code] I think it's something to do with my web.xml file.
Listing of my web.xml file: [code] <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2se/dtds/web-app_2_2.dtd">
<web-app> <!-- Application that implements Wireless security for GSM networks in this case, Nigeria -->
<display-name>Wireless Security application</display-name> <description> This application uses a client - server model to implement a Wireless security mechanism for GSM networks. </description>
<!-- I'm supposed to declare parameters here, but chose not to, yet -->
<servlet> <servlet-name>HelloServlet</servlet-name> <description> This servlet does this and this..... </description> <servlet-class>mypackage.HelloServlet</servlet-class> <init-param> <param-name>NoParameter</param-name> <param-value>NoValue</param-value> </init-param> <load-on-startup>5</load-on-startup> </servlet>