Servlet request.getParameter() returns 空

Servlet request.getParameter() returns null

我已经阅读了所有关于此的问题,但我仍然没有任何进展。我想将输入字段的值传递给我的 servlet,但 servlet 的 request.getParameter returns 为 null,而不是输入的内容。这是我的 HTML:

<form method="post" action="MyHttpServletDemo" id="myForm">
    <input type="text" id="input" name="input1" placeholder="    Input coordinates...">
</form>
    <a href="welcome"><button type="button" id="vnes" onclick="Vnes()">Search</button></a>

这是我的。xml:

<servlet>
<servlet-name>MyHttpServletDemo</servlet-name>
<servlet-class>MyServletDemo</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyHttpServletDemo</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>

Servlet:

public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

      response.setContentType("text/html");

      PrintWriter out = response.getWriter();
      
      String value = (String) request.getParameter("input1");
      out.println("<h1>" + value + "</h1>");
   }

我试过这个:

   public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
      PrintWriter out = response.getWriter();
      String value = (String) request.getParameter("input1");
      out.println("<h1>" + value + "</h1>");
   }

HTML:

<form method="post" action="/welcome" id="myForm">
    <input type="text" id="input" name="input1" placeholder="    Input coordinates...">
 <a href="welcome"><button type="button" id="vnes" onclick="Vnes()">Search</button></a>
</form>

还是不行。

成功了!这是解决方案: HTML:

<form method="get" action="welcome" id="myForm">
    <input type="text" id="pole" name="pole1" placeholder="    Input coordinates...">
    <button type="submit" id="vnes">Search</button>
</form>

.xml 文件:

<servlet>
<servlet-name>MyHttpServletDemo</servlet-name>
<servlet-class>MyServletDemo</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyHttpServletDemo</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>

Servlet:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      String value = (String) request.getParameter("pole1");
      out.println("<h1>" + value + "</h1>");
}