[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Regarding GET & POST

Posted on 2005-05-06
Medium Priority
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
  • 5
LVL 29

Accepted Solution

bloodredsun earned 2000 total points
ID: 13943726
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

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

package com.bloodredsun.dev;

import java.io.IOException;
import java.io.PrintWriter;

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 servlet.do?name=ernie
            //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

ID: 13943858
other common causes are mispelling the doPost and doGet methods and calling super(request, response) in either of these methods.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Expert Comment

ID: 13969376
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.


Expert Comment

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

Expert Comment

ID: 15534271
Anything going on here?
LVL 29

Expert Comment

ID: 15557263

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
Last month Marc Laliberte, WatchGuard’s Senior Threat Analyst, contributed reviewed the three major email authentication anti-phishing technology standards: SPF, DKIM, and DMARC. Learn more in part 2 of the series originally posted in Cyber Defense …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 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