This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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)
jQuery in Action, 2nd edition
subject: Post / Get
Similar Threads
use doGet & doPost Method
Basic Question about Service Method
Doubts in HTTP Methods behaviour
doubt in servlet
HFS&J Question on page 118