This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes HTTP method POST is not supported by this URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTTP method POST is not supported by this URL" Watch "HTTP method POST is not supported by this URL" New topic

HTTP method POST is not supported by this URL

Sudhir V
Ranch Hand

Joined: Dec 25, 2002
Posts: 143
I have made a form with "post" request
<form action="servlet/form1_servlet" method="post">
State: <select name="state" size=3 multiple>
<option value="NJ">New Jersey</option>
<option value="OK">Oklahoma</option>
<input type="submit" value="click">
and the action specifies the servlet below. I am getting this error "HTTP method POST is not supported by this URL" when I click the button in the page. however the servlet works fine when I change the request to "get".
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class form1_servlet extends HttpServlet
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
PrintWriter pw = res.getWriter();
String val = req.getParameter("state");

Sudhir V<br />(SCJP 1.2, SCWCD, OCA, SCBCD)
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
You need to implement the doPost() method in your servlet.
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
if you want your servlet to do the same thing when it gets both post and get requests
the best practice is not to implement service(), but to implement doGet(request,response)
and to implement doPost the next way:
this way you cover both doPost and doGet

Asher Tarnopolski
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
Actually I'd rather re-route both doGet() and doPost() to a third method called "doService()" or something like that just in case you decide you want to change the behavior of one or the other in the future.
However, this still doesn't explain why sudhir's implementation doesn't work -- HttpServlet implements service(HttpServletRequest,HttpServletResponse) by calling doGet() and doPost(). By overriding it in his method, he should have short-circuited this behavior.
Sudhir, is this a copy-cut-and-paste of your exact code, or did you rewrite it in your post? Perhaps you made a spelling error in the name of the method?

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
yeh, kyle is right, the code must work.
so, may be the problem is the deployment?
where do you put your html anf the servlet files?
did u try to make the form target begin with "/"?
It is sorta covered in the JavaRanch Style Guide.
subject: HTTP method POST is not supported by this URL
It's not a secret anymore!