wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Can not run a servlet class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Can not run a servlet class" Watch "Can not run a servlet class" New topic
Author

Can not run a servlet class

newworld kingdom
Greenhorn

Joined: Jun 21, 2003
Posts: 10
1)Apache Tomcat/4.1.24,
2)install_dir/webapps/root/web-inf/classes/HelloServlet.class
3)http://host/servlet/HelloServlet
But get HTTP Status 404
What should I do?
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
I am not sure about the fix,
should (3) be
http://localhost:8080/servlet/HelloServlet ?
Originally posted by newworld kingdom:
1)Apache Tomcat/4.1.24,
2)install_dir/webapps/root/web-inf/classes/HelloServlet.class
3)http://host/servlet/HelloServlet
But get HTTP Status 404
What should I do?


not so smart guy still curious to learn new stuff every now and then
newworld kingdom
Greenhorn

Joined: Jun 21, 2003
Posts: 10
Yes,the (3) is http://localhost:8080/servlet/HelloServlet
and I removed the comment on
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
but it doesn't work.
Anyone knows this? Thanks lot!
Amer Khan
Ranch Hand

Joined: Apr 05, 2003
Posts: 163
Better way of doing this:
click here!


<i>Dare to dream - everything that exists today,was once a figment of someone's imagination, nobody says tomorrow can't be a figment of your today.</i>
newworld kingdom
Greenhorn

Joined: Jun 21, 2003
Posts: 10
Thanks Amer and Chi.
not work until now,
by the way,http://localhost:8080 will display
"The page cannot be displayed".
but http://IP address of my machine:8080 is allright. (3) is http://IP address of my machine:8080/servlet/HelloServlet.
Does it matter? and Why I can not use localhost?
Amer Khan
Ranch Hand

Joined: Apr 05, 2003
Posts: 163
which operating system r u using?
win 2000 or 98

I think there is a problem with your classpath.
newworld kingdom
Greenhorn

Joined: Jun 21, 2003
Posts: 10
Amer,thank you so much,the OS is win2000,
the classpath is .;D:\j2sdk14\lib\tools.jar;D:\Tomcat 4.1\common\lib\servlet.jar;D:\j2sdk14;D:\j2eesdk14\lib\j2ee.jar;D:\j2eeProgram;D:\j2eesdk14
Amer Khan
Ranch Hand

Joined: Apr 05, 2003
Posts: 163
I am using jdk1.3.
tomcat installation directory is ---tomcat

CLASSPATH
.;d:\tomcat\common\lib\servlet.jar
HERE tomcat is the name of tomcat installation directory.
PATH
d:\jdk1.3\bin
CATALINA_HOME
d:\tomcat
HERE tomcat is the name of tomcat installation directory.
JAVA_HOME
d:\jdk1.3

OR/and
Edit setclasspath.batch file located at tomcat>bin>setclasspath.batch:
here set java_home like this:
set JAVA_HOME=d:\jdk1.3
This batch file looks like this:
rem ---------------------------------------------------------------------------
rem Set CLASSPATH and Java options
rem
rem $Id: setclasspath.bat,v 1.8 2003/01/17 10:07:21 remm Exp $
rem ---------------------------------------------------------------------------
rem Make sure prerequisite environment variables are set
if not "%JAVA_HOME%" == "" goto gotJavaHome
set JAVA_HOME=d:\jdk1.3 <---------------------------------------------HERE
:gotJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javaw.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
goto okJavaHome
[ June 24, 2003: Message edited by: Amer Khan ]
Amer Khan
Ranch Hand

Joined: Apr 05, 2003
Posts: 163
To confirm your settings
type:
http://localhost:8080/
Enter
u should get the default tomcat home page.
If everything is ok type:
http://localhost:8080/servlet/yourservletclass
newworld kingdom
Greenhorn

Joined: Jun 21, 2003
Posts: 10
Thank you,Amer!
Now http://63.189.70.202:8080/servlet/HelloServlet is OK, 63.189.70.202 is my PC's IP,but http://localhost:8080/servlet/HelloServlet failed.
Anyway,you solved this problem ! Thanks!
Meghasyam Bokam
Greenhorn

Joined: Feb 27, 2003
Posts: 16
Hi newworld,
I am also getting the same 404 error when i am type the url on my browser as:
http://localhost:8080/chapter01/servlet/HelloWorldServlet
Did u find out the problem?


Regards,<br />Meghasyam.<p>SCJP1.4
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
Hi,
have you tried to uncomment the following line in
tomcat-install-dir/conf/web.xml ?
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
it is around line 273 in the web.xml.
HTH
Meghasyam Bokam
Greenhorn

Joined: Feb 27, 2003
Posts: 16
hi chi lin,
Thanks a lot. Now its working after uncommenting the servlet mapping element.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can not run a servlet class