It's not a secret anymore!
The moose likes Servlets and the fly likes Post / Get Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Post / Get" Watch "Post / Get" New topic

Post / Get

Nick Lebian

Joined: May 30, 2003
Posts: 9
What must I change, if I want to use doPost instead of doGet? I'm using tomcat and my little test-programm looks like this:
import javax.servlet.http.*;
import javax.servlet.*;
public class HitServlet extends HttpServlet
private int mCount;

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
String message = "Hits: " + ++mCount;
// response.setContentType("text/plain");
// response.setContentLength(message.length());
// PrintWriter out = response.getWriter();
// out.println(message);
But the programm only runs with the doGet method, with the doPost method the browser shows this error message:
HTTP method GET is not supported by this URL
Why? Thanks.
Calina Cazangiu
Ranch Hand

Joined: Feb 27, 2003
Posts: 30
Add a doPost method where you could call doGet.
Calina Cazangiu
Ranch Hand

Joined: Feb 27, 2003
Posts: 30
Maybe I misunderstood your question - it complains when you have a doPost but no doGet? Then it's the way you call the servlet. If you call the servlet directly from your browser, the default method is doGet. If you want to use doPost, use an html file where you specify method="POST" (again, get is the default)
I agree. Here's the link:
subject: Post / Get
It's not a secret anymore!