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

servlet 404 error

vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
hi ranchers.

just now i started to learn servlets. am going on with head first servlet and jsp book. i tried my hello world servlet in that. i deployed the same structure. but am getting 404 error. my web.xml is right, my java program got compiled without errors. i dont know where am wrong. help me out.
thank you..


Regards,
vignesh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

"vignesh",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
check mapping of your url to the servlet in web.xml


Amit Tank
Linked In
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9350
    
    2

After making changes try restarting your container...


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
when ever i make a change to the web.xml, am restarting tomcat. but still am not able to do it. My program compiles fine. i ve set the environmental variables both CATALINA_HOME AND JAVA_HOME.. I checked the web.xml the url-pattern. still i get only 404.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9350
    
    2

Then try accessing the sample applications in Tomcat and see if you still get a 404...if not, then try checking the throughly the files names you used to configure in web.xml and the actual files.
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 176
Try setting class path to your webapplication's classes folder, it will work...


Kiran Kumar.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by bnkiran kumar:
Try setting class path to your webapplication's classes folder, it will work...


He already said that it compiled without errors.
This is a runtime issue.
Tomcat ignores your configured classpath and builds its own at runtime.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

vignesh hariharan,

Post your web.xml file and the URL that you're using when you try to access your servlet.
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 176
Ben,

We have class files only in classes folder right, then there is no need to think about compilation. May be containter was not able to find classes,if we give classpath upto the webapplications classes directory it will work....
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by bnkiran kumar:
Ben,

We have class files only in classes folder right, then there is no need to think about compilation. May be containter was not able to find classes,if we give classpath upto the webapplications classes directory it will work....


As said before, Tomcat ignores your classpath environment variable.
It finds classes by looking in a list of directories.

More importantly, he's not reporting a ClassNotFoundException, he's reporting a 404 error. More likely than not, his servlet has not been configured properly. This is why we need to see his servlet mapping and the URL that he's using.
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
You might want to try checking the tomcat log or the console when tomcat starts up to see if it had any problems deploying your web application.
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
hi ranchers..

thank you so much for your replies..
sorry for delay in reply.

C:\Tomcat 5.5\webapps\ch1\WEB-INF --- In this location my web.xml is present.
C:\Tomcat 5.5\webapps\ch1\WEB-INF\classes --- In this location my Ch1Servlet.class is present.

My Ch1Servlet.java compiles fine. so no compile time error.. As I told its only 404 error I get.




CATALINA_HOME=C:\Tomcat 5.5
JAVA_HOME=C:\jdk1.6.0
classpath=;C:\Tomcat 5.5\common\lib\servlet-api.jar;.

URL which i give in browser is http://localhost:8080/ch1/Serv



All these I have set in My computer-> Properties

please help me out where am wrong.

regards
vignesh
[ June 29, 2007: Message edited by: vignesh hariharan ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Why is the servlet class not in a package?
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
This is just my hello world program.. I thought i can just place it in webapp->class.. Is it compulsory to make it placed inside a package???
Biswajit Paria
Ranch Hand

Joined: Feb 02, 2003
Posts: 46
This is just my hello world program.. I thought i can just place it in webapp->class.. Is it compulsory to make it placed inside a package???


be sure that you have servlet class file(make a jar file) in lib folder in WEB-INF ..
Saravanan Thoppae
Greenhorn

Joined: Jun 30, 2007
Posts: 13
A basic check. Did you try accessing the examples provided by tomcat first? This is just to check whether your server is really listening to your request at 8080 and you have not installed any other servers (like weblogic/websphere) which has already seized 8080.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Originally posted by Biswajit Paria:


be sure that you have servlet class file(make a jar file) in lib folder in WEB-INF ..


That is not necessary.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Originally posted by vignesh hariharan:
This is just my hello world program.. I thought i can just place it in webapp->class.. Is it compulsory to make it placed inside a package???


Have you tried it yet?
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
Till now i dint give it a try...
Neha Gap
Greenhorn

Joined: May 30, 2007
Posts: 29
I tried doing the same thing using WSAD but it gives me the same error. JSPs get displayed correctly and so do static pages, the error only occurs with the servlets. Any ideas?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

Originally posted by vignesh hariharan:
Till now i dint give it a try...


No time like the present!
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi All,

Recently I too had a similar problem with my Tomcat and tried reinstalling it couple of times but still it didn't work out. How ever after googling on this problem, I tried this and it worked out.

Vignesh did you try checking server.xml file. Did you add <Context> tag into that detailing about your application docbase and path. I know this tag would be set to avoid restarting the server every time we recompile the servlet, but not for the current problem. But it worked for me. Also please recheck the case sensitivity of your servlet class names and other stuff in your web.xml , as that was also my mistake . Refer the link http://www.onjava.com/pub/a/onjava/2001/04/19/tomcat.htmlbelow
vignesh hariharan
Ranch Hand

Joined: Jun 23, 2005
Posts: 77
hey ranchers,

hi Bear.. a special thanks to you. Just now I tried. But i dint put it in any package. still it worked out.

Really thanks a lot.
But am really sorry. I dont know how i did mistakes so silly..
But let this help others.

I will list out my mistakes.

I saved my web.xml using wordpad and it saved it in its default format as Rich text format. so what happened is, eventhough i saved it "web.xml" the rich text format added few additional formating features, extra features and stuffs. so my web.xml was not read properly by the container.

I was so careful in the content but was a bit careless in this saving stuffs.

Also i dint declare my class as public. But this exception i got it after correcting my web.xml.

sorry ranchers.
thanks a lot for your help.
[ June 30, 2007: Message edited by: vignesh hariharan ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Thank you for posting back with the answers.

Two things:
1.)
Get yourself a real text editor if you're going to write code.
Windows ships with two of them and they're both junk.
There are lots of good ones out there (TextPad, JPad, UltraEdit, GVIM, Emacs, etc..)

2.) See:
http://faq.javaranch.com/view?PackageYourBeans
There have been some changes in the JVM (after 1.4.0) that keep servlet/jsp apps from finding some classes if they are in the default package. Some things can be found (in this case your servlet) but others can not. The reasons why aren't that complicated but the easiest and simplest solution is simply to make sure ALL of your classes are in a package.
Vyas Sanzgiri
Ranch Hand

Joined: Jun 16, 2007
Posts: 686

Use Netbeans!


===Vyas Sanzgiri===
My Blog
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Display name is showing up now, thanks. The other pages will update in due course.
Arun Kumar Gupta
Ranch Hand

Joined: Jul 16, 2008
Posts: 33
hi ...after searching many topics i got this one.I am facing the similar problem running my first servlet .I am using JDK1_5_0_06,tomat 5.5.26.

The servlet i wrote compiled correctly:

package firstservlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class ch1servlet extends HttpServlet {

public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException {

response.setContentType("text/html");
PrintWriter out= response.getWriter();
java.util.Date today=new java.util.Date();
out.println("<html>"+"<body>"+"<h1 align=center> HF chapter1 Servlet</h1>"+"<br>"+today+"</body>"+"</html>");
}
}
--------------------------------------------------------------------
the web.xml file is as:

<?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>chap1servlet</servlet-name>
<servlet-class>firstservlet.ch1servlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>chap1servlet</servlet-name>
<url-pattern>/serv1</url-pattern>
</servlet-mapping>
</web-app>

--------------------------------------------------------------------

the path i am using for web.xml and class file is :

C:\arundata\tomcat5\apache-tomcat-5.5.26\webapps\ch1\web.xml
C:\arundata\tomcat5\apache-tomcat-5.5.26\webapps\ch1\WEB- INF\classes\firstservlet\ch1servlet.class

In the tomcat homepage ,i can run servlet-examples correctly and using tomcat manager i can see the /ch1 is running

but when i use http://localhost:8080/ch1/serv1 i got the

http status 404 ,the requested resource is unavailable.

Waiting for valueable suggestion of follow ranchers


SCJP 1.4<br />SCWCD 1.5
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4176
    
  21

Originally posted by Arun Kumar Gupta:

C:\arundata\tomcat5\apache-tomcat-5.5.26\webapps\ch1\web.xml
C:\arundata\tomcat5\apache-tomcat-5.5.26\webapps\ch1\WEB- INF\classes\firstservlet\ch1servlet.class


The web.xml should be in:

C:\arundata\tomcat5\apache-tomcat-5.5.26\webapps\ch1\WEB-INF\web.xml


Steve
Arun Kumar Gupta
Ranch Hand

Joined: Jul 16, 2008
Posts: 33
thats it ....Thanks a lot steve ...i am working on this silly mistake from last two days but this never come into my mind.Really like to thank you and keep up the good work of helping novice like me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet 404 error