in that myContext folder I've created WEB-INF folder in that classes and lib folders like this
C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26\webapps\ROOT\myContext\WEB-INF\classes
and
C:\Program Files\Apache Software Foundation\Apache Tomcat 6.0.26\webapps\ROOT\myContext\WEB-INF\lib
Now in myContext I've created main.html page which calls to servlet TemplateServlet.class file which is stored in classes folder
but I see your servlet class name is -'TemplateServlet'
Post by:William Brogden
, Rancher
A common beginner error. ALL classes used in servlets should be in a package and the class file in the corresponding directory.
The reason being that without an explicit package, the JVM looks in the "current" directory - something you have no control over.
Bill
Post by:Ganesh Pat
, Ranch Hand
@ Divya I dunno but what i have learned according to that when click on Submit button it will submit test then it will go to web.xml file and in that in servlet mapping means here
it will search url-pattern test and now here we have url pattern test and now will see servlet-name i.e template and this name will be mapped to servlet-name in <servlet> here in below code
and when it matched to servlet -name i.e template it will go for servlet class file name i.e TemplateServlet and will search this TemplateServlet.class file in WEB-INF /classes folder in classes folder I have TemplateServlet.class i.e compiled java file now it will run that thats what i have been told
Dunno whether I'm correct or not but please correct me if I'm wrong
Post by:Ganesh Pat
, Ranch Hand
@ William Will you please elaborate it. I haven't understood which files to be put in which folder.
See I have webapps/ROOT folders.
In this ROOt folder I kept my html page
Ex. ROOT/Prog2.html and
In ROOT folder I have create WEB-INF folder in this folder I have web.sml file which do mapping n all.
Ex. ROOT/WEB-INF/web.xml
In same WEB-INF folder I have created a folder named classes which contains .class file
Ex. ROOT/WEB-INF/classes/TemplateServlet.class
Please correct me if i'm wrong
Post by:Ganesh Pat
, Ranch Hand
@ T Mishra ya sure friend. I didn't know that . What do you mean Try adding fully qualified class name for TemplateServlet. sorry didn't get that please explain.
Post by:K. Tsang
, Bartender
Based on the config setup, it looks ok. The servlet class in the web.xml file should be the fully qualified name (with package if any).
The culprit is in your servlet code. You only have a doGet() method. And your html form is using POST. Changing the doGet to doPost should get your output when the form is submitted.
If you don't use the form at all and just type in the servlet url, you should get your output. Try it.
Post by:Ganesh Pat
, Ranch Hand
k. Tsang ya i will try it now thank you
Post by:William Brogden
, Rancher
All classes used in servlets MUST be in a package or you get confusing errors.
The package name MUST be used in the directory structure for the .class file, so if your servlet package is "my.spot"
Instead of locating it in
you MUST use a path under classes that shows the package name - that is how the servlet container finds and loads the class.
Bill
(confusion may result from looking at older references which used the dreaded Invoker Servlet supposedly to make things easier but actually confusing generations of programmers)
Post by:Ganesh Pat
, Ranch Hand
@ William Thanks a lot for help. I will try with this
Post by:Ganesh Pat
, Ranch Hand
OMG !! hey friends It wasn't a problem of my code. I've successfully run this program with same code as typed at the beginning and also got correct output.
You know the problem was in version of Tomcat. Actually I had run above program using jakarta-tomcat-5.5.9. I installed that and copied all files as I mentioned above and deleted all content of web.xml and copied this in that
that's it it ran I will figure out soon It was really problem of Tomcat version or content of my web.xml file
Post by:Ganesh Pat
, Ranch Hand
Finally got the answer it wan't problem of tomcat version. It ran because of the <web-app xmlns="http://java.sun.com/j2ee/xml/ns" version="2.4">
this code. Thank you all for your valuable support.
Post by:K. Tsang
, Bartender
Ganesh Pat wrote:Finally got the answer it wan't problem of tomcat version. It ran because of the <web-app xmlns="http://java.sun.com/j2ee/xml/ns" version="2.4">
this code. Thank you all for your valuable support.
If your web.xml is using (servlets) 2.4, then your web app is developing against J2EE 1.4.
If you use a newer version of Tomcat, ideally it should work because it's backward compatible.
Post by:autobot
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Thread Boost - a very different sort of advertising