Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Karthikeyan Pandian
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • 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


 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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".
 
Suresh KumarPandey
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • 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







 
Ron McLeod
Saloon Keeper
Posts: 1424
206
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!