Why does this code gives HTTP Status 405 - HTTP method GET is not supported by this URL ? I think I'm directly calling servlet so by default it searches for doGet() method. If I remove comment from doGet() method that time also it gives same error rather printing Called doGet in html tag. any solution please ?
All classes used in servlets or JSP should be in a package - otherwise you get errors. Reason being that the JVM looks for a class without a package in the "current" directory, something you have no control over.
That error is thrown by the doGet method in HttpServlet - the usual base class - because you have not provided an overriding doGet.
@ Aditya No I'm not using any html page to call this servlet. I'm directly compiling this servlet and calling it by its url using Tomcat server. At the beginning I need to understand how actually JSP and servlet works and their flow so now notepad and command line, later IDE for sure.
Yes I think by default It searches for doGet method. It worked when I changed doPost to doGet.
All classes used in servlets or JSP should be in a package
But It's giving error HTTP Status 500 - TenNumbers/MyTenRandomNumber (wrong name: MyTenRandomNumber), when I place MyTenRandomNumber.class file in TenNumbers folder.
Here is location of MyTenRandomNumber.class file:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\PrintTenNumbers\WEB-INF\classes\TenNumbers\MyTenRandomNumber.class
Location of web.xml file: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\PrintTenNumbers\WEB-INF\web.xml
If you don't understand packages you need to stop trying to do servlets until you have mastered the basics.
No, I know packages and had done similar servlet program before but forgot to mention in this, thank you William. It worked
yes I'll do more & more practice on notepad and do all configuration stuff manually...
Being Java programmer.
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad: