• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets 404 error

 
Arajeshh Kumara
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello rancher,
I am trying to run servlet program from 1 week..still i am getting HTTP 404 when i am trying to run the application..please correct my problem.

I have installed JDK1.5 and Tomcat 5.5 and
in environment variables i have set the path is classPath=c:\tomcat\common\lib\servlet-api.jar;c:\tomcat\common\jsp-api.jar;
path c:\jdk1.5\bin;
JAVA_HOME=c:\jdk1.5;
CATALINA_HOME=c:\tomcat;

This is my servlet program


i have successfully compiled the servlet program and placed webapps\servletex\WEB_INF\classes\

and web.xml is placed in webapps\servletex\WEB_INF\

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>ServletDemo</servlet-name>
<servlet-class>ServletDemo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletDemo</servlet-name>
<url-pattern>/ServletDemo</url-pattern>
</servlet-mapping>
</web-app>

i started the server and clicked my folder name i m getting the 404 error..........and i have typed the url http://localhost:8080/servletex/ServletDemo
still i m getting the same error..i.e. 404 error


so guys please help me...



[BSouther: Added UBB CODE tags]
[ January 11, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't looked very closely but the first thing that jumps out is the mis-spelling of the method name "doGet". You've spelled it "doget".

Java is a case sensitive language and will not find your doGet method if the casing is not exact.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and web.xml is placed in webapps\servletex\WEB_INF\


Also, it's "WEB-INF", not WEB_INF".
You need a hyphen, not an underscore.
Tomcat probably never deployed this application because it didn't find a WEB-INF directory.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, before you go much further, you should see this.

You might be able to get this servlet running without putting it in a package but you're going to run into trouble later on when you try to write beans and other components unless you get in the habit of packaging all of your Java classes. The default package (no declared package) was meant for trivial command line applications and should not be used in a web application.
[ January 11, 2008: Message edited by: Ben Souther ]
 
Arajeshh Kumara
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry to say those are my typing mistakes...I have corrected still am getting the same error...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You made the typing mistakes in your app or when posting to JavaRanch?

If you've just corrected the mistakes in your app, you'll need to recompile your servlet class and restart your application (or all of Tomcat, if that's easier).


If you made the typing errors when posting to the Ranch, you should read this for tips on avoiding the need to type things directly into the Javarach pages.
Doing so is error prone and is a waste of time.
 
Arajeshh Kumara
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am so sorry..

I have compiled the application and restarted the server...still getting the same error..do I need to change server.xml or web.xml in tomcat conf.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a default install of Tomcat, no, you shouldn't need to change anything in the conf directory.

Have you checked the Tomcat Manager application to see if your application was deployed?
http://localhost:8080/manager/html

Also, have you checked the logs under tomcat/logs to see if there are any errors deploying your application?
 
Arajeshh Kumara
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My Application has been deployed...I have seen my Application folder in tomcat manager. when click the folder the application shows the error HTTP status 404 error. So please reply me. If you solve my problem i will be glad thankful to you..
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ALL java classes used in servlets should be in a package to avoid exactly this problem.

What does your web.xml look like now?
Where is the compiled class placed?
How are you addressing the servlet?

Bill
 
Arajeshh Kumara
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my web.xml looks like now

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>

</web-app>

my application is placed in
C:\Tomcat\webapps\serlvetexx\WEB-INF\classes\ServletDemo.java

I have addressed in web.xml is
<servlet-class>ServletDemo</servlet-demo>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read William's response regarding packages?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arajeshh Kumara:

my application is placed in
C:\Tomcat\webapps\serlvetexx\WEB-INF\classes\ServletDemo.java


You need to compile ServletDemo and put the '.class' file in the classes directory. The container doesn't pay any attention to you source ('.java') files.

Also two people have told you about packaging your Java classes and you haven't acknowledged either of them on this issue. Are you ignoring this advice or are you not sure what it means to package your Java classes?
 
Arajeshh Kumara
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yah i have placed my .class file in that classes folder...

And i have used package in .java application and compiled..and I have i modified my web.xml as

<servlet-class>packagename.ServletDmo</servlet-class>
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arajeshh Kumara:
yah i have placed my .class file in that classes folder...

And i have used package in .java application and compiled..and I have i modified my web.xml as

<servlet-class>packagename.ServletDmo</servlet-class>


What the ranchers have been telling is packaging your class files in a structured manner rather than letting them belong to the default package.

I believe you are sure about the "default package" Vs "explicit package". As such your latest post shows that you have created a package named "packagename" and you have made your "ServletDmo" [Is the name misspelled here this time?] part of this "packagename" by declaring the



Is that what you have done? I think Ben had already pointed you to Post the real code rather than you manually typing here which may deviate to further confusions.

Kindly pay some attention to the answers what you get and spend some time to read the contents in the links provided to you.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Arajeshh Kumara:
yah i have placed my .class file in that classes folder...

And i have used package in .java application and compiled..and I have i modified my web.xml as

<servlet-class>packagename.ServletDmo</servlet-class>




So...
Is your class file in the classes folder or is it in a folder that matches the name of your package (which should be in the classes folder)?

WEB-INF/classes/packagename/ServletDemo.class

As Raghavan Muthu has stated, every time you post a misleading or contradictory message, you waste the time of the people who are trying to help you. Eventually, they will start ignoring your questions altogether.
Be very careful not to waste people's time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic