inf
inf

Reputation: 21

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 ?

Upvotes: 0

Views: 41

Answers (2)

dushyant nasit
dushyant nasit

Reputation: 41

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

Add a name to your input box

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

Upvotes: 0

Vincent Passau
Vincent Passau

Reputation: 822

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>

Upvotes: 2

Related Questions