HTTP method GET is not supported by this URL type Servlet Error

usaa error 405: http method get is not supported by this url
http method get is not supported by this url in eclipse
http method get is not supported by this url directv
the server responded with a status of 405 http method post is not supported by this url
http method post is not supported by this url wildfly
http status 405 – method not allowed tomcat
request method 'get' not supported in postman
the specified http method is not allowed for the requested resource.

I am creating a Simple Sales System using Jsp Ajax. When I add the data click Add button all Html Table data is successfully pass in to the salesadd Servlet Page I see on the console I receving data look like this format to Servlet Page

[{"item":"Chocolate","pro_price":"32","qty":"1","total":"32"}, {"item":"Mango","pro_price":"10","qty":"1","total":"10"}]

But data is not add to the database and show the error like this. I wrote the Full Error below.

HTTP method GET is not supported by this URL type Status report messageHTTP method GET is not supported by this URL descriptionThe specified HTTP method is not allowed for the requested resource.

What I tried so now I attached Below.i think might be the problem with the Product Class

Product.java

public class Product 
{ 
    private String item;
    private int price;  
    private int qty;  
    private int total;   
    public String getItem()
    {
        return item;
    }
    public void setItem(String item)
    {
        this.item = item;
    }
     public int getPrice()
    {
        return price;
    }

    public void setPrice(int price)
    {
        this.price = price;
    }
     public int getQty()
    {
        return qty;
    }
    public void setQty(int qty)
    {
        this.qty = qty;
    }

      public int getTotal()
    {
        return total;
    }

    public void setTotal(int total)
    {
        this.total = total;
    }  
}

Servlet Page

salesadd.java

@WebServlet("/salesadd")
public class salesadd extends HttpServlet {
    Connection con;
    PreparedStatement pst;
    int row;
   protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    doPost(request, response);

     Connection con;
    PreparedStatement pst; 
    String jsonData = request.getParameter("data1");
    PrintWriter out = response.getWriter();

     Gson gson = new Gson();
    Product data1 = gson.fromJson(jsonData, Product.class);
    String item = data1.getItem();
    int price = data1.getPrice();
    int qty = data1.getQty();
    int total = data1.getTotal();




     try 
    {
        con = DriverManager.getConnection("jdbc:mysql://localhost/icepos", "root", "");
        pst = con.prepareStatement("insert into sale_product(item,price,qty,total)values(?,?,?,?) ");
        pst.setString(1, data1.getItem());
        pst.setInt(2, data1.getPrice());
        pst.setInt(3, data1.getQty());
        pst.setInt(4, data1.getTotal());
        pst.executeUpdate();

        out.println("<font color='green'>  Record Adddd   </font>");
    } catch (SQLException ex) {
        out.println("<font color='red'>  Record Failed   </font>");
    }

}







public void doPost(HttpServletRequest req,HttpServletResponse rsp ) throws IOException,ServletException
{
    rsp.setContentType("text/html");
      PrintWriter out = rsp.getWriter();


     out.println("<font color='green'>  Record Adddd   </font>");

}

you can loop the list, like follow:

for (Product product : objectList) {
        try
        {
            con = DriverManager.getConnection("jdbc:mysql://localhost/icepos", "root", "");
            pst = con.prepareStatement("insert into sale_product(item,price,qty,total)values(?,?,?,?) ");
            pst.setString(1, product.getItem());
            pst.setInt(2, product.getPrice());
            pst.setInt(3, product.getQty());
            pst.setInt(4, product.getTotal());
            pst.executeUpdate();

            out.println("<font color='green'>  Record Adddd   </font>");
        } catch (SQLException ex) {
            out.println("<font color='red'>  Record Failed   </font>");
        }
    }

getting error HTTP Status 405, The HTTP status 405 is a very common error message in Java Servlet. HTTP Status 405 - HTTP method GET is not supported by this URL type� When, we write method="get" in form action, doGet () is written in Servlets, if method="post", then doPost () is written. But your error "HTTP method GET is not supported by this URL" is wired because your code form action and doPost () method is correct. I think some configuration are wrong in web.xml. Please change below code in your web.xml.

HttpServlet class has another method doGet. You can override the method, so support the GET request

HTTP Status 405 - HTTP method GET is not , Status 405 - HTTP method GET is not supported by this URL public class PersonObject extends HttpServlet but I am getting error like this The typical way to do a POST type request is with an HTML form where the form� message HTTP method GET is not supported by this URL description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL)." Can anybody help me out in dis??? my servlet code is as follows:

Your client side (from browser) is making a GET request and since you don't have a doGet() method, you are receiving this error.

Although you may add a doGet() method in your class but that will not solve the problem for your use case. You need to send a POST request from your client (check your AJAX code on client side). The GET request is not supposed to have body rather it should have only the requested URL with query parameters.

Further, I see you are trying to map your client sent data

[{"item":"Chocolate","pro_price":"32","qty":"1","total":"32"},
 {"item":"Mango","pro_price":"10","qty":"1","total":"10"}]

to an object of product class using following

Product data1 = gson.fromJson(jsonData, Product.class);

This will fail as you are are sending an array of products. For a starter just send one JSON object like following

{"item":"Chocolate","price":"32","qty":"1","total":"32"}

Once you make this work, before implementing for your use case, have a read of any GSON tutorial to get a better idea. One tutorial can be found here

As a side note, you should not declare conn, pst etc as class member variables, bring them down in method. Also, close the connection in a final block after try and catch.

Status 405, http status 405 http method get is not supported by this url servlet i got this error plz tell me. type Status report message HTTP method GET� type Status report. message HTTP method GET is not supported by this URL. description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL). -3. I think its cause due doGet methid is not override by youoverride doGet methode in servlet Code

you json string is array, but you parse to a object. So you need to parse to a List. Follow:

@Test
public void testGson(){
    String jsonStr = "[{\"item\":\"Chocolate\",\"pro_price\":\"32\",\"qty\":\"1\",\"total\":\"32\"}, {\"item\":\"Mango\",\"pro_price\":\"10\",\"qty\":\"1\",\"total\":\"10\"}]";
    List<Product> objectList = getObjectList(jsonStr, Product.class);
    System.out.println(objectList);
}
public static <T> List<T> getObjectList(String jsonString,Class<T> cls){
    List<T> list = new ArrayList<>();
    try {
        Gson gson = new Gson();
        JsonArray arry = new JsonParser().parse(jsonString).getAsJsonArray();
        for (JsonElement jsonElement : arry) {
            list.add(gson.fromJson(jsonElement, cls));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return list;
}

http status 405 http method get is not supported by this url servlet , 405 ERROR (GET METHOD IS NOT SUPPORTED BY THIS URL) in Solved Error Duration: 5:52 Posted: Nov 20, 2016 message HTTP method GET is not supported by this URL description The specified HTTP method is not allowed for the requested resource (HTTP method GET is not supported by this URL).

How to solve HTTP status 405 ERROR (GET METHOD IS NOT , The 405 Method Not Allowed is an HTTP response status code indicating A 404 Not Found error indicates that the requested resource could not be server to accept a GET request at that resource/URL, so it may respond with a through , depending on what type of server your application is running on:. Hey, I need some help with a javascript code. The code works fine a in HTML editor but produces this error, “HTTP method GET is not supported by this URL” in WordPress.

405 Method Not Allowed: What It Is and How to Fix It, HTTP Status 405 - HTTP method GET is not supported by this URL only shows that the process moved on the next servlet. but why im getting the http status 405 ? Can you show the HTML that causes the error code? out.println( " <input type='button' value='Login' name='login' onclick='verify();''>" );. Sometimes Developers facing the HTTP STATUS 405 ERROR during the development. Here in this video we will learn that how can we solve this problem HTTP STATUS 405 ERROR in NetBeans. If you are also

HTTP Status 405, HTTP Status 405 - HTTP method POST is not supported by this URL. Keywords: by Kevin Jansz at 4:26 pm. Labels: error messages, HTTP, servlets, tomcat� The HttpServlet basically follows the template method pattern where all non-overridden HTTP methods returns this HTTP 405 error "Method not supported". When you override such a method, you should not call super method, because you would otherwise still get the HTTP 405 error. The same story goes on for your doPost () method.

Comments
  • thanks awesome work sir . really well developer sir u.
  • after displayed the Record Adddd msg i need pass in to print.jsp how to call it sir
  • you can use the spring boot + mybatis that I advice. It is very simple and quick
  • spring boot: spring mybatis: mybatis.org. you can follow the guide or search by google
  • com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path this error also displyed
  • sir i did what the way you told me that but no error . record is not addedd
  • return "Student [ item: "+item+", pro_price: "+ pro_price+ ",qty: "+qty+", total: "+ total+ " ]";
  • you use the follow method to parse json string:public static <T> List<T> getObjectList(String jsonString,Class<T> cls){ List<T> list = new ArrayList<>(); try { Gson gson = new Gson(); JsonArray arry = new JsonParser().parse(jsonString).getAsJsonArray(); for (JsonElement jsonElement : arry) { list.add(gson.fromJson(jsonElement, cls)); } } catch (Exception e) { e.printStackTrace(); } return list; }
  • [Product [ item=Chocolate, pro_price=32, qty=1, total=32], Product [ item=Chocolate, pro_price=32, qty=1, total=32]] now out display like this sir. i need set String item = objectList.item but i couln't i need to add values in to the database
  • you mean you can't insert values to DB?
  • yes i cannot insert values how to insert the values sir String item = objectList.item how to get the item from list