Regarding GET & POST

Posted on 2005-05-06
Last Modified: 2010-04-01
When I try to run my servlet on the address bar if I use either doPost or doGet it gives me error for both saying that POST(GET) method not supported by URL.

Can I know the reason for this problem?

Question by:icbwubr
    LVL 29

    Accepted Solution

    have you mapped the servlet properly in the web.xml?

    Have you implemented/overridden the methods doPost(HttpServletRequest request, HttpServletResponse response) and doGet(HttpServletRequest request, HttpServletResponse response) in your servlet?

    Also check you haven't protected your methods, i.e. other jsps and servlets work.

    Posting your servlet code would help.
    LVL 29

    Expert Comment

    Here's a basic servlet to make sure that your servlet/jsp container is working


    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    public class TestServlet extends HttpServlet {
          public void init(){
                //any initlializing: none here

          public void doGet( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //example of getting the session
                HttpSession session = request.getSession() ;
                session.setAttribute( "status" , "friend" ) ;
                //example of getting a request parameter i.e. url section like this
                //also with null check via a ternary operator to provide a default
                String paramName = request.getParameter("name")!= null ? request.getParameter("name"): "stranger" ;
                //example of writing some content
                PrintWriter out = response.getWriter();
                out.println("<html><head><title>A Simple Servlet</title></head><body>");
                out.println("Hello " + paramName );
          public void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                doGet( request, response);
    }//end TestServlet

    web.xml snippet
            <!-- more servlets if any-->


    Remember that you need to compile the servlet code into a class file which should be placed according to it's package under the classes folder e.g.

    and also that in the web.xml, the order of the elements is important and that your must put all your <servlet> declarations before any <servlet-mapping> decalrations
    LVL 29

    Expert Comment

    other common causes are mispelling the doPost and doGet methods and calling super(request, response) in either of these methods.
    LVL 3

    Expert Comment

    Authors Comments:

    >>When I try to run my servlet on the address bar

    First of all when u invoke a servlet using a URL in address bar your doGet() method gets called and not doPost().
    (No need to override doPost() in that case)

    The above sample code by bloodredsun to write a servlet should help u.

    -- See to it that ur Servlet Gets compiled succesfully. check ur code n map it accordingly. And also know how to invoke the servlet. :-o with the mapped path.

    LVL 3

    Expert Comment

    Also check the security constraints in your web.xml.
    LVL 29

    Expert Comment

    Anything going on here?
    LVL 29

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    After several days of searching and hunting for limited documentation, I wanted to share this guide to hopefully save someone the hassle of trying to figure this out on their own. I have tested this on Xendesktop 7.1 and PS 4.5 running simultaneous…
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now