Java: Use GET and POST in the same Form


What I want to do is send the parameters from Form to POST and then through the method GET consult the BBDD for room availability and send that result through Ajax (Vanilla Javascript) to HTML But from what I was seeing I can not use the methods at the same time. It only works if I only use the method POST (method="POST") or only the method GET (method="GET") on the Form.

Here is the query Ajax :

function loadDoc() {
                var xhttp = new XMLHttpRequest();
      "GET", "Controlador", true);
                xhttp.setRequestHeader('Content-Type', 'text/html');
                xhttp.onreadystatechange = function () {
                    if (this.readyState === 4 && this.status === 200) {
                        document.getElementById("precio").innerHTML = this.responseText;



And here the method doGet :

        PrintWriter out = response.getWriter();

        ReservaDAOImp rv = new ReservaDAOImp();

        out.print(rv.disponibilidad("select disponibilidad from T_tiphab where tipo=? and codHotel=?", rsv));

When I use the method GET in Form send me to another page with the   correct result but when I use it with Ajax the parameters of the   form arrive NULL to Servlet.

asked by TOMAS 13.03.2018 в 20:37

1 answer


Basically what you should do is capture the submit event of the form and do something in it. As an example we will show the following form

<form action="/action_page.php" method="post" onsubmit="funcionAdicional()">
    function funcionAdicional(){
        // ejecutar función  GET

By adding the event handler onsubmit you can execute code when the form is sent.

answered by 14.03.2018 в 00:18