Difficulties with setting up Apache tomcat: 'Need a little help.
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Greetings everyone,
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.
After starting tomcat, I point my browser to http://127.0.0.1:8080/examples/servlet/HelloWorldExample to bring up the HelloWorld example servlet. But when I do: http://127.0.0.1:8080/gsmsecurity/servlet/HelloServlet I get a tomcat error report page: HTTP status 404.
When I try different urls e.g http://127.0.0.1:8080/gsmsecurity/HelloServlet, the result is the same. Even when I put HelloWorldExample inside my classes folder and tried to bring it up, I didn't succed. My conclusion was that this was probably because there was no web.xml file in the WEB-INF folder. I put a minimal amount of things in the xml file and put it up, but the problem persists.
I would appreciate it greatly if someone could tell me what I'm doing wrong here.
Here's a listing of my Servlet. It's s simple one to let me know everything OK,before serious work begins
A listing of my web.xml file:
his is the song tomcat sings anytime it starts up:
My environment variables:
Another question I have is, why does http:\\localhost:8080\blah,blah not work for me?
Maybe it would also help if I mention that I am running Windows 2000 professional without IIS installed.
Thanks for reading up to this point. You could as well kindly pass a comment or two.......
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.
After starting tomcat, I point my browser to http://127.0.0.1:8080/examples/servlet/HelloWorldExample to bring up the HelloWorld example servlet. But when I do: http://127.0.0.1:8080/gsmsecurity/servlet/HelloServlet I get a tomcat error report page: HTTP status 404.
When I try different urls e.g http://127.0.0.1:8080/gsmsecurity/HelloServlet, the result is the same. Even when I put HelloWorldExample inside my classes folder and tried to bring it up, I didn't succed. My conclusion was that this was probably because there was no web.xml file in the WEB-INF folder. I put a minimal amount of things in the xml file and put it up, but the problem persists.
I would appreciate it greatly if someone could tell me what I'm doing wrong here.
Here's a listing of my Servlet. It's s simple one to let me know everything OK,before serious work begins
A listing of my web.xml file:
his is the song tomcat sings anytime it starts up:
My environment variables:
Another question I have is, why does http:\\localhost:8080\blah,blah not work for me?
Maybe it would also help if I mention that I am running Windows 2000 professional without IIS installed.
Thanks for reading up to this point. You could as well kindly pass a comment or two.......
I used to be SCJP
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Try adding a <servlet-mapping> entry in your web.xml file.
Also its a good idea, as well as good practice, to put your serlvet class in a package.
Also its a good idea, as well as good practice, to put your serlvet class in a package.
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
You appear to be using URLs with "/servlet/" in them. This gets you involved with the "invoker" servlet.
Read this FAQ here at the ranch and find out why this is a bad idea.
As Richard said - it is essential to put all classes involved in servlets in a package.
Bill
Read this FAQ here at the ranch and find out why this is a bad idea.
As Richard said - it is essential to put all classes involved in servlets in a package.
Bill
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
u can try this out...c if this works..
add the following in ur web.xml after <\servlet>
- <servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
and then use the following url to access the servlet
http://127.0.0.1:8080/gsmsecurity/HelloServlet
add the following in ur web.xml after <\servlet>
- <servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
and then use the following url to access the servlet
http://127.0.0.1:8080/gsmsecurity/HelloServlet
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Moving this thread to the more appropriate Apache/Tomcat forum.
Mark
Mark
Femi Alla
Ranch Hand
Posts: 86
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks so much for those answers.
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
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:
<!-- The mapping for the invoker servlet -->
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
-->
[/code]
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
-->
<context-param>
<param-name>myParameter</param-name>
<param-value>myValue</param-value>
<description>
This parameter represents nothing sensible......
</description>
</context-param>
<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>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/gsm</url-pattern>
</servlet-mapping>
<session-config>
<!-- How long to wait before the session times out-->
<!-- 30 minutes -->
<session-timeout>30</session-timeout>
</session-config>
</web-app>
[/code]
Any useful suggestion would be greatly appreaciated.
Thanks.
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
you linked me to and I got the message.The Long and Sordid Tale of the Invoker Servlet
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
-->
<context-param>
<param-name>myParameter</param-name>
<param-value>myValue</param-value>
<description>
This parameter represents nothing sensible......
</description>
</context-param>
<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>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/gsm</url-pattern>
</servlet-mapping>
<session-config>
<!-- How long to wait before the session times out-->
<!-- 30 minutes -->
<session-timeout>30</session-timeout>
</session-config>
</web-app>
[/code]
Any useful suggestion would be greatly appreaciated.
Thanks.
I used to be SCJP
posted 21 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
Your url to invoke the servlet must be like
http://localhost:8080/myapp/HelloServlet
Check u have the right folder structure like
ur web.xml must be some thing like
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
and ur server.xml..verfiy u have added ur application
<Context path="/myapp" docBase="myapp" debug="7" reloadable="true">
</Context>
These are the things u need to run a servlet from ur context(ie an application like myapp)
and abt Invoker servlet..since now u have mapped the servlet,its no longer required.If the mapping is not done (prior to tomcat 4) ur URL to invoke servlet will be like http://localhost:8080/myapp/servlet/HelloServlet
i'm just putting all the points which i learned recently
Chandrasekhar S
[ September 29, 2004: Message edited by: Chandra Sekhar ]
Your url to invoke the servlet must be like
http://localhost:8080/myapp/HelloServlet
Check u have the right folder structure like
ur web.xml must be some thing like
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
and ur server.xml..verfiy u have added ur application
<Context path="/myapp" docBase="myapp" debug="7" reloadable="true">
</Context>
These are the things u need to run a servlet from ur context(ie an application like myapp)
and abt Invoker servlet..since now u have mapped the servlet,its no longer required.If the mapping is not done (prior to tomcat 4) ur URL to invoke servlet will be like http://localhost:8080/myapp/servlet/HelloServlet
i'm just putting all the points which i learned recently
Chandrasekhar S
[ September 29, 2004: Message edited by: Chandra Sekhar ]
"Luck is when opportunity meets preparation"
| Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











