• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Post / Get

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
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.*;
import java.io.*;
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.
Bye,
Nick
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add a doPost method where you could call doGet.
 
Calina Cazangiu
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic