为什么request.getParamether在JSP中不起作用

时间:2019-06-04 08:44:47

标签: java jsp servlets java-ee tomcat7

您好,我无法从index.jsp文件中的from中获取任何值。我正在使用tomcat7,在运行index.jsp并单击“发送”按钮后,什么都没有发生。 System.out.prinln()打印nothinig或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);
%>

你知道我在做什么错吗?

2 个答案:

答案 0 :(得分:2)

此行允许您使用其名称而不是其 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>

答案 1 :(得分:0)

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

在输入框中添加名称

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