java - 为什么request.getParamether在jsp中不起作用

标签 java jsp servlets jakarta-ee tomcat7

您好,我无法从我的index.jsp 文件中的a 中获取任何值。我正在使用 tomcat7,运行 index.jsp 并单击发送按钮后没有任何反应。 System.out.prinln() 不打印任何内容或 null ;(

index.jsp

%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body>
  <form acton="addnewtask.jsp" method="post" >
        <label for="name">Name</label>
          <input type="text" class="form-control" id="name" placeholder="Name">
      <button type="submit" class="btn btn-danger">Add</button>
  </body>
</html>

addnewtask.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>


<%
    String s  = request.getParameter("name");
    System.out.println(s);
%>

你知道我做错了什么吗?

最佳答案

此行允许您获取带有名称而不是id的参数:

 String s  = request.getParameter("name");

在您的输入中添加名称并更正表单属性操作的拼写错误:

  <form action="addnewtask.jsp" method="post" >
      <label for="name">Name</label>
      <input name="name" type="text" class="form-control" id="name" placeholder="Name">
      <button type="submit" class="btn btn-danger">Add</button>
  <form>

关于java - 为什么request.getParamether在jsp中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56440352/

相关文章:

java - Interleave - 在 Java 中不能正常工作

java - 在 Spark 中读取自定义序列文件

java - jpa @manytoone 创建复合主键而不是 @id

jsp - Struts无法从jsp目录访问jsp

java - web.xml 中的 url-pattern 无法识别多个 url

javascript - 如何获取通过 servlet 中的 jquery 添加的动态填充列表的值

java - JTextField 和 JTextArea 在程序运行时随机不工作

php - .html v/s jsp/php/etc 的 SEO 优势?

java - SpringMVC Controller 错误

java - 检查客户端机器上是否有cookie,否则你做一些事情并退出