Cant find the Class file

Hi,

My JSP file is in Root/webapps and my class file and java file is in ROOT/webapps/WEB-INF/classes....now in my jsp my HTML tag is

<form action="/connectToDatabase" method="post>

now i m getting http 404 error saying that it cannot find the file. i tried all kind of paths but cant seem to work......what should i do? my tomcat is 5.5.9...your reply would be appreciated">

[409 byte] By [Bhavika] at [2007-10-3 0:16:18]
# 1
are you submitting it to a class file only or a servlet?
jgalacambraa at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for the prompt reply,actually the Java file is not a servlet but just a file which checks the data from the database
Bhavika at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
to be precise....calling the class file(java file)...its not a servlet....
Bhavika at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
the action should be on a servlet or jsp .. the class file will be called by the servlet or jsp..
jgalacambraa at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
well the jsp file is calling a servlet which is in WEB-INF/classes....but still cant find it....i appreciate your reply but please help me here...i can redirect frm jsp to another jsp but i still need to call the servlet(java file) from the WEB-INF/classes
Bhavika at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

First thing, your class needs to be in a package. Classes in the "unnamed" package are no longer accessible from Tomcat.

package mypackage;

public class MyClass { ...

would then compile to: /WEB-INF/classes/mypackage/MyClass.class

How are you trying to call this class?

evnafetsa at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
your java class should be called from within a servlet.. url mappings only work when the class implement httpServlet...
ketsona at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
if yu are calling a servlet, the servlet should be declared in the web.xml so the application can see it
jgalacambraa at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

First of all thank you jgalacambra, evnafets and ketson for replying.

Now according to your instructions i have placed the servlet in the package myPackage. i have also declared the servlet in web.xml...now my servlet is in WEB-INF/classes/myPackage/ConnectionToDatabase.class

my JSP is in webapps/ROOT directory..

i m calling the servlet from this JSP and the code for it is

<form action="/myPackage/ConnectionToDatabase" method="post">

still i m getting the error stating

http 404 error

Bhavika at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

part of your web.xml should at lest look like this:

<servlet>

<servlet-name>MyServlet</servlet-name>

<servlet-class>myPackage.MyServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>MyServlet</servlet-name>

<url-pattern>/myServlet</url-pattern>

</servlet-mapping>

calling upon the servlet is (assuming tomcat):

http://localhost/myapp/myServlet

jgalacambraa at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

> i m calling the servlet from this JSP and the code

> for it is

>

> <form action="/myPackage/ConnectionToDatabase"

> method="post">

>

the value of the action attribute should correspond to whatever you have included in your url-mapping element as stated in the reply by jcalambra...

there is no need for you to have /mypackage/ConnectionToDatabase...

if <url mapping>/Servlet</url=mapping>

then in your form, you should only have

<form action="/Servlet"as opposed to...

form action="/myPackage/ConnectionToDatabase"

i think thats where the problem resides.. the web.xml needs to be properly configured and the form attributes changed to reflect the new values...

hope this helps>

ketsona at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

Thank you Ketson and jgalacambra for helping me out....i m getting null pointer exception but i will solve that problem...main thing is atleast now its calling the servlet...thank you i previoulsy changed the web.xml and declared the servlet but didnt write the <servlet-mapping>

<servlet-name>MyServlet</servlet-name>

<url-pattern>/myServlet</url-pattern>

</servlet-mapping>

option..

Please keep up the good work and appreciate for your help

Bhavika at 2007-7-14 17:07:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...