Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • 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
Eclipse IDE MySQL Database Tomcat Server Java
  • 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
 
Greenhorn
Posts: 17
Eclipse IDE Slackware Linux
  • 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
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • 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.
 
Author and all-around good cowpoke
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
Eclipse IDE MySQL Database Tomcat Server Java
  • 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
Eclipse IDE MySQL Database Tomcat Server Java
  • 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
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
Eclipse IDE MySQL Database Tomcat Server Java
  • 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...
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic