Executing my first servlet program

Hello ranchers, I am trying to learn j2ee, servlets and Ejb. i am having a nightmare in running my first servlet program. Here is how my TestingServler looks like. here is the directory where i stored my .java file C:\jakarta-tomcat-5.0.14\webapps\myApp\WEB-INF\classes

and here is my web.xml file which i have placed in C:\jakarta-tomcat-5.0.14\webapps\myApp\WEB-INF

1. You mean the .class file, right ? You have compiled the servlet and put the .class file here, right ? Don't put java files in your classes directory. 2. You'd better put your servlet in a package, instead of putting it right under classes. 3. You need to define a <servlet-mapping> tag to map a url to your servlet. Try it, and if you still don't understand how to define it, come back

There should be a <servlet-mapping> element in your web.xml Regards, Srikkanth.M

Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70

posted May 23, 2007 23:34:00

0

satou thanks for the reply. after hours of debugging i have left my laptop alone and will do it tomorrow morning. I was just following the steps in the book and they state to put java files in the classes directory. Lets see if i can put it in a package and then run the servlet file.

Ok Here i am back again. Looks like i had to bug myself for a long time. I did uncomment the lines as stated in the url(invoker servlet) and i have added the mapping also for the servlet, but still it is not compiling

type Status report

message /myApp/Testing

description The requested resource (/myApp/Testing) is not available.

Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70

posted May 25, 2007 15:58:00

0

ok glad i am able to run my first servlet program after hours and hours of debugging. OMG i hate authors of some books.

ANyways one more question and i guess i am all set to go to learn about j2ee . Excited and happy. I was wondering if i created an xml file web.xml just for that specific TestingServlet.java file where do i save it and how do i run it.

Herman PS: if you use Tomcat 5, it's easier to use a book that also uses Tomcat 5. Your book uses Tomcat 4, and somethings just work differently... [ May 25, 2007: Message edited by: Herman Scheltinga ]

Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70

posted May 25, 2007 16:28:00

0

Herman yes you are right. Step4 will teach you about the deplyment descriptor but its not working. I dont know why. any idea?

Suleman zia
Ranch Hand

Joined: Apr 19, 2007
Posts: 70

posted May 25, 2007 16:30:00

0

OMG It worked. Yayyyyy.

took me 9 hours to run this simple program oh well lets see what happens when it comes to JBoss and JDBC.

Thanks

Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387

posted May 26, 2007 06:54:00

0

hi,

what did you do to make it work?

I hope you did this(from your book) "To create the deployment descriptor, you now need to create a web.xml file and place it under the WEB-INF directory under myApp."