Hello.

There was a need to do something on the JS button by clicking a button on the form and then start the servlet.

How is this possible to do?

ps

tried

document.location.href="${pageContext.request.contextPath}/NewServlet"; 

But error 405 occurs

 HTTP Status 405 - HTTP method GET is not supported by this URL
 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.

I realized the error with the lack of a GET handler in NewServlet.

Immediately another question arose how to change the GET method to POST in JS, if it is possible of course?

  • 1. We intercept the standard event of pressing the button. 2. We stop the distribution of the event as soon as we intercepted it. 3. We do what we need. 4. Either via AJAX or otherwise call the servlet. - DimXenon pm
  • If on the bare JS there is no desire to write - you can connect jQuery. There with AJAX everything is great. And with DOM you can work comfortably. - DimXenon

1 answer 1

Do something in JS, cause

 document.forms['form-name'].submit(); 

In the form will be so

 <form method="POST" action="/folder/some-url.htm" >