• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Status 405 - HTTP method GET is not supported by this URL  RSS feed

 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ?
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml file

PrintTenNumbers is application folder which contains WEB-INF folder.
Location of MyTenRandomNumber.class file: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\PrintTenNumbers\WEB-INF\classes\MyTenRandomNumber.class
Location of web.xml file: C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\PrintTenNumbers\WEB-INF\web.xml

Url I'm using to call this servlet is: http://localhost:8080/PrintTenNumbers/printno
 
Aditya Mukundan
Greenhorn
Posts: 17
Eclipse IDE Linux Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm seeing post given in your servlet.Did you mention get method in your form tag ?Start using an IDE to do web apps.like eclipse or net beans...it's much better and convenient
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have not implemented doGet method in your servlet, so 405 error is thrown.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<servlet-class>MyTenRandomNumber</servlet-class>


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.

Bill


 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ 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.
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

I used this url to call the servlet MyTenRandomNumber.class:
http://localhost:8080/PrintTenNumbers/printno

MyTenRandomNumber.java:


web.xml:
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your package declaration in the MyTenRandomNumber.java file?

If you don't understand packages you need to stop trying to do servlets until you have mastered the basics.

Bill
later IDE for sure.
Don't try to use an IDE until you are comfortable with the basics - IDEs do stuff behind your back.
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!