Конечно, вы можете сделать это. Ниже приведен пример:
TestDoPost. java:
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/TestDoPost")
public class TestDoPost extends HttpServlet {
private static final long serialVersionUID = 1L;
public TestDoPost() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html; charset=UTF-8");
response.getWriter().write("Success!");
}
}
NewFile. html:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<form action="TestDoPost" method="post">
<input type="submit">
</form>
</body>
</html>
Разверните приложение и нажмите кнопку Submit
в файле HTML. Ниже приведен результат:
![enter image description here](https://i.stack.imgur.com/7JCqZ.png)
![enter image description here](https://i.stack.imgur.com/wrPkD.png)