• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

servlet 404 error

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check mapping of your url to the servlet in web.xml
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After making changes try restarting your container...
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try setting class path to your webapplication's classes folder, it will work...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is the servlet class not in a package?
 
vignesh hariharan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ..
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Till now i dint give it a try...
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



No time like the present!
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 coderanch. 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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 686
Netbeans IDE Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use Netbeans!
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Display name is showing up now, thanks. The other pages will update in due course.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Arun Kumar Gupta
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic