aspose file tools*
The moose likes Tomcat and the fly likes servlet configuration problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "servlet configuration problem" Watch "servlet configuration problem" New topic
Author

servlet configuration problem

Yichuan Wang
Greenhorn

Joined: Jan 17, 2008
Posts: 8
Hi everyone, I am new to this forum.
I come across a problem when I was doing the example from "Head First Servlet and JSP"(page 30-31).

I wrote a Servlet (HelloWorldTest), compiled it (no error) and placed it
in :I:\Web\Tomcat 6.0\webapps\ROOT\Test\WEB-INF\classes
THe WEB-INF file is placed
in: I:\Web\Tomcat 6.0\webapps\ROOT\Test\WEB-INF

When I tried to access the servlet using:
http://localhost/Test/hello
got the following message
Not Found

The requested URL /Test/hello was not found on this server.


Servlet File:


Here is my WEB-INF file:

Anybody can tell me what is wrong with my code??
thanks very much
[ January 19, 2008: Message edited by: Bear Bibeault ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I:\Web\Tomcat 6.0\webapps\ROOT\Test\WEB-INF\classes

Please move your application under webapps, not under ROOT :
I:\Web\Tomcat 6.0\webapps\Test\WEB-INF\classes

Also, you'll probably have to access Tomcat at port 8080 :
http://localhost:8080/Test/hello


[My Blog]
All roads lead to JavaRanch
Yichuan Wang
Greenhorn

Joined: Jan 17, 2008
Posts: 8
Originally posted by Christophe Verre:

Please move your application under webapps, not under ROOT :
I:\Web\Tomcat 6.0\webapps\Test\WEB-INF\classes

Also, you'll probably have to access Tomcat at port 8080 :
http://localhost:8080/Test/hello


Thanks for your reply,
first, can you please tell me why should I move it to webapp directory?
isn't the ROOT directory supposed to be the default directory for WWW access??

I use both apache and Tomcat for WWW accessing on my machine, where
Apache is for rendering static html, Tomcat is for JSP and servlets.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Originally posted by Yichuan Wang:

isn't the ROOT directory supposed to be the default directory for WWW access??

No, webapps is.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yichuan Wang
Greenhorn

Joined: Jan 17, 2008
Posts: 8
Originally posted by Christophe Verre:

Please move your application under webapps, not under ROOT :
I:\Web\Tomcat 6.0\webapps\Test\WEB-INF\classes

Also, you'll probably have to access Tomcat at port 8080 :
http://localhost:8080/Test/hello


I tried it in your way, and it works,
but I've got a new question:it works when I use
http://localhost:8080/Test/hello
but if use http://localhost/Test/hello, then the error message
pops up again.
Lave Kulshreshtha
Ranch Hand

Joined: Oct 21, 2007
Posts: 106
Every application server has dedicated ports for various kinds of services.
In your case 8080 is the default port which is used to access www application.

-Lave

Originally posted by Yichuan Wang:


I tried it in your way, and it works,
but I've got a new question:it works when I use
http://localhost:8080/Test/hello
but if use http://localhost/Test/hello, then the error message
pops up again.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, ITIL V3 Foundation Certification
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Yichuan Wang:


I tried it in your way, and it works,
but I've got a new question:it works when I use
http://localhost:8080/Test/hello
but if use http://localhost/Test/hello, then the error message
pops up again.




The default port for non-secure HTTP is 80.
If you don't specify a port the browser will automatically use port 80.

For a couple reasons, Tomcat ships with its default port set to 8080.
You can change it by editing your tomcat/conf/server.xml file.
Look for the <Connector ... /> entry that its port attribute set to 8080 and change it to 80. Restart Tomcat and you can use the URL that you mentioned.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Hui Zhao
Ranch Hand

Joined: Jul 09, 2007
Posts: 116
[Removed hi-jack]

Hui Zhao,
It is better to ask your question in a new thread than to potentially hijack this one with a similar but different question.
[ January 20, 2008: Message edited by: Ben Souther ]
Yichuan Wang
Greenhorn

Joined: Jan 17, 2008
Posts: 8
Originally posted by Ben Souther:




The default port for non-secure HTTP is 80.
If you don't specify a port the browser will automatically use port 80.

For a couple reasons, Tomcat ships with its default port set to 8080.
You can change it by editing your tomcat/conf/server.xml file.
Look for the <Connector ... /> entry that its port attribute set to 8080 and change it to 80. Restart Tomcat and you can use the URL that you mentioned.

Hi Ben, thanks for your reply,
I think now I found out why http://localhost:8080/Test/hello works where http://localhost/Test/hello doesn't. but I still don't know how to fix it yet. The reason for why port 80 doesn't work is because Apache can not handles Servlet properly. It appears that it can properly handles JSP and Do files but not Servlets, there could be something wrong with the configuration of the helper program(Jakarta Tomcat connector).
I have both Tomcat and Apache installed on my desktop, an additional helper
software(Jakarta Tomcat connecter) is also installed which connects Apache with Tomcat.
When there is a static html page, apache handles it, and when there is a JSP page apache passes it over to Tomcat.


When I use port 80(Apache):
It works perfectly when it processes JSP pages, but it just can not process servlets.

This is the configuration I added to Apache httpd.conf


anybody could possibly tell me why?
or should I change line:JkMount /servlet/* ajp13
to something else?
[ January 20, 2008: Message edited by: Yichuan Wang ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you're using something more than just Tomcat, it's a good idea to mention that upfront. I didn't know that you were connecting Tomcat to the Apache Web Server till now.


These days, I use Tomcat as a standalone so I'm out of practice when it comes to connecting it to other web servers.

Maybe someone else can assist you in getting the two to cooperate.
Yichuan Wang
Greenhorn

Joined: Jan 17, 2008
Posts: 8
Originally posted by Ben Souther:
If you're using something more than just Tomcat, it's a good idea to mention that upfront. I didn't know that you were connecting Tomcat to the Apache Web Server till now.


These days, I use Tomcat as a standalone so I'm out of practice when it comes to connecting it to other web servers.

Maybe someone else can assist you in getting the two to cooperate.


Sorry about the confusion, I should have mentioned that at the very beginning, but I did not know this was the cause of the problem.

hope somebody else could know more about the problem.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'm going to move this to our Apache / Tomcat forum.

The forum covers Tomcat more than the Apache Web Server but someone there might be able to help you with the connector configuration.
Yichuan Wang
Greenhorn

Joined: Jan 17, 2008
Posts: 8
Originally posted by Ben Souther:
I'm going to move this to our Apache / Tomcat forum.

The forum covers Tomcat more than the Apache Web Server but someone there might be able to help you with the connector configuration.


Yes please, and I desperately need answers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet configuration problem