Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi mate's

I got a error as "HTTP Status 405 - HTTP method POST is not supported by this URL" .. i shuffled by changing the methods between get and post but both yielded the same error. I saw lot of blogs and tried to make changes as per the people comments but ended up with the same result. Kindly, help me out. I have just pasted the code below.


Welcome.html


 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll likely find the info you need here. Yes, the error code is different, but the causes are similar.

Hint: Packages are important, and so is letter-case.

btw, "servlet" is a poor name choice for a servlet. Use a descriptive name that tells you something about what the servlet does, even if it's just "/MyHelloWorldServlet".
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Change the Welcome.html like this
</head>
<body>
<form action="servlet" method="post">
User Name:<input type="text" name="uname">
<input type="submit" value="Submit">
</form>
</body>
</html>

Change the web.xml file

<welcome-file-list>
<welcome-file>Welcome.html</welcome-file>

</welcome-file-list>

<servlet>

<servlet-name>Servlet</servlet-name>
<servlet-class>Servlet.java.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>


It will work







 
Marshal
Posts: 3825
537
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The parameters for the doPost method (and all other service methods) are HttpServletRequest, HttpServletResponse. You have them reversed.
 
Karthikeyan Pandian
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys..

Actually my error is solved...

I just added
public void doGet(HttpServletResponse res, HttpServletRequest req) throws ServletException, IOException
{
doPost(req,res);
}

Then I got the output

 
Rancher
Posts: 43027
76
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I doubt that that change alone solved anything. I advise to familiarize yourself with the @Override annotation, and use that whenever you think you're overriding a method. it's a real time saver.

Besides, treating GET and POST interchangeably violates the HTTP specification, and you may well run into problems.

And lastly, you need to get into the habit of putting your classes into packages. It won't be long until you'll run into trouble if you don't.
 
What's that smell? I think this tiny ad may have stepped in something.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic