File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes 404 error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "404 error" Watch "404 error" New topic
Author

404 error

jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
I'm just starting out with JSP's and servlets.

I'm the latest Tomcat container.

I'm trying to set up a simple login example (taken from O'reilly's ONJAVA pages)

Here is my web.xml entry:


I would like to access my login.class servlet from my login.jsp page.

Here is the <FORM> entry of my login.jsp page:



My form has a SUBMIT button. When I press it I am expecting my servlet to get executed, but instead, I get a 404 error:



Any idea what I could have done wrong here?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Originally posted by jeff ukridge:

...



The servlet name and the form's "action" (both in bold here) need to match. The form should change to use "login" as the action.


[Jess in Action][AskingGoodQuestions]
jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
Thanks for the response. Unfortunately it didn't change the error:



Here is my directory structure in my TOMCATHOME/webapps:

in webapps/WRNR:



in the WEB-INF:


And then in classes there are furthere subdirectories:
/com/WRNR

and finially in WRNR is my class:





I was thinking that it could be a permissions problem?

Or maybe I need my web.xml file modified to include a <servlet-mapping> tag?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You'll need to create a servlet-mapping entry in your web.xml file.

Check out this thread.
I just posted an example web.xml file with a servlet-mapping to it.
http://www.coderanch.com/t/361660/Servlets/java/call-servlet


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
I'm new to this so I'm a little confused.

What would my <servlet-mapping> look like?

Like this maybe:



I'm not sure that's right...

how about something like this:




I'm not at my system right now, or I would give these a try. I'll be at my system again in a few hours.
jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
nothing changing here..I still can't get rid of the 404 error.

Here is the current state of the project.

In TOMCAT_HOME/conf/server.xml:



in TOMCAT_HOME/webapps/WRNR/login.jsp:




in TOMCAT_HOME/webapps/WRNR/WEB-INF/web.xml:



My servlet is in TOMCAT_HOME/webapps/WRNR/WEB-INF/classes/com/WRNR


And the error is:


I've tried many different permutations here. Does anyone see an error anywhere?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

And what are you using for the form action now?
jeff ukridge
Greenhorn

Joined: Nov 21, 2005
Posts: 16
ok...2 days later, it seems as if the smoke has cleared.

My problems turned out to be that I had a mistake in my web.xml file.

Also ( I think ) that I needed to use the manager/html application to restart my servlet after I modified the web.xml.


Anyway, clearly my biggest mistake was to not include my complete web.xml to this forum. Somone would have seen a typo there a lot faster than I did.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 404 error
 
Similar Threads
Tomcat 5.0 FORM authentication + servlet mapping problem
Getting started with JSP-Servlet using apache-tomcat-5.5.17
problem with FORM based authentication
Servlet not showing up in Browser
need help with declarative security