Q:

"HTTP Status 405 – HTTP method GET is not supported by this URL" error when calling servlet from JSP

I have the following code, but when I try to access the /data-upload URL I get the error "HTTP method GET is not supported by this URL".
Java servlet code:
package xyz.controllers;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.entity.StringEntity;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.annotation.WebServlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

@WebServlet("/data-upload")
public class GetLocalAreaIds extends HttpServlet {

    // HTTP POST request
    public void doPost(HttpServletRequest request, HttpResponse response) throws ServletException, IOException {  
        System.out.println("#VH in doPost method ");
        String url = "http://xyz.xyz/search";

        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(url);

        // add header
        post.setHeader("Content-Type", "application/xml");

        String elementLocalNameType = request.getParameter("elementLocalNameType");
        System.out.println("#VH elementLocalNameType: " + elementLocalNameType);

        String localAreaName = request.getParameter("localAreaName");
        System.out.println("#VH localAreaName: " + localAreaName);

        StringEntity params = null;
        try {
            params = getStringEntityParams(elementLocalNameType, localAreaName);
            System.out.println("#VH params: " + params);
        }
        catch (Exception e) {
            System.out.println("Error while getting elementLocalNameType");
        }

        post.setEntity(params);
        response = client.execute(post);
        System.out.println("\nSending 'POST' request to URL : " + url);
        System.out.println("Post parameters : " + post.getEntity());
        System.out.println("Response Code : " +
                response.getStatusLine().getStatusCode());

        BufferedReader rd = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent()));

        StringBuffer result = new StringBuffer();
        String line = "";
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }

        System.out.println("#VH result.toString(): " + result.toString());
    }

    public void doGet(HttpServletRequest request, HttpResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    private StringEntity getStringEntityParams(String elementLocalNameType, String localAreaName) throws Exception {
        StringEntity params = new StringEntity("<request><workflow>get-element-values-workflow</workflow><get-element-values><element-localname>"+elementLocalNameType+"</element-localname><starts-with>"+localAreaName+"</starts-with><is-csv>True</is-csv></get-element-values></request>");
        return params;
    }
}

JSP code:
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<%@ taglib prefix="user" uri="/WEB-INF/tlds/user.tld" %>

<%@ page import="org.apache.http.client.HttpClient" %>
<%@ page import="org.apache.http.client.methods.HttpGet" %>
<%@ page import="org.apache.http.impl.client.DefaultHttpClient" %>
<%@ page import="GetLocalAreaIds" %>

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<tiles:insertDefinition name="layout">
    <tiles:putAttribute name="title">Title</tiles:putAttribute>

  <tiles:putAttribute name="main">

        <main id="content" role="main" class="group category-page">
            <header class="page-header group">
                <div class="full-width">
                    <h1>Data Upload</h1>
                </div>
            </header>

            <div class="browse-container full-width group">
                        <div id="error">
                        <p style="color: #ff0000">${error}</p>
                </div>

                <user:current-local-area msg="<b>LA:</b> !{#localAreaName}"/>

                <c:set var = 'la_id' scope = 'session' value = '<user:current-local-area msg="!{#localAreaName}">'/>

                <c:set var = "la_id"><user:current-local-area msg="!{#localAreaName}"/></c:set>

                <jsp:useBean id="GetLocalAreaIds" class="GetLocalAreaIds"/>

                <form action="${pageContext.request.contextPath}/data-upload" method="POST">
                  <span>Do you want to download the LA IDs for families or individuals?</span><br />
                  <input type="radio" name="elementLocalNameType" value="la-family-id"> Family IDs<br />
                  <input type="radio" name="elementLocalNameType" value="la-individual-id"> Individual IDs<br />
                  <input type="hidden" name="localAreaName" value="${la_id}">
                  <input class="button" type="submit" value="Submit">
                </form>

            </div>

        </main>
        </tiles:putAttribute>
  </tiles:insertDefinition>

I have read some of the other posts which deal with the same issue, but their solutions didn't work for me.  When I try adding @Override to the doPost and doGet methods, I get an error saying "method does not override or implement a method from a supertype" even though I'm extending HttpServlet.

A:

The issue is, both get and post are not inherited from the HttpServlet
change the
doPost(HttpServletRequest request, HttpResponse response)

to
doPost(HttpServletRequest request, HttpServletResponse response)

and
doGet(HttpServletRequest request, HttpResponse response)

to
doGet(HttpServletRequest request, HttpServletResponse response)

EDIT
Next issue is
response = client.execute(post);

which as you stated "incompatible types: org.apache.http.HttpResponse cannot be converted to javax.servlet.http.HttpServletResponse"
Change it to
org.apache.http.HttpResponse my_response = client.execute(post);
...
System.out.println("Response Code : " +
                my_response.getStatusLine().getStatusCode());

        BufferedReader rd = new BufferedReader(
                new InputStreamReader(my_response.getEntity().getContent()));

Also note, you don't write anything to user response out, so if you get nothing in calling client(e.g. browser) it's normal. Or you write everything you do with stdout with response out.

