Search code examples
javajspservletsjakarta-eetomcat7

Why request.getParamether don't work in jsp


Hello i can't get any value from a from in my index.jsp file. I'm using tomcat7, after running index.jsp and clicking send button nothing happen. System.out.prinln() print nothinig or 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);
%>

Do you know what am i doing wrong ?


Solution

  • This line allows you to get a parameter with its name not its id :

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

    Add a name to your input and correct the typo of the attribute action of your form :

      <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>