Im trying to send a form of my HTML table that contains three input text with the same name.Then calc the sum in Servlet and see the table with the three input text with the values and the Result of 3 input text in JSP, How can I do it?.

This is how I post the form.

<html>

<FORM action="calc.jsp" method="post">
<table>
    <tr>
        <td><input value="0" name="val" /></td>
        <td><input value="0" name="val"/></td>
        <td><input value="0" name="val"/></td>
    </tr>
</table>
<INPUT type="submit" value="Send">
</FORM>
</html>

This is my class Where I get the array:

public class Calcs {

    private String[] val;

    public String[] getVal() {
        return this.val;
    }
    public void setVal(String[] value) {
        this.val = value;
    }

Thanks.

有帮助吗?

解决方案

In the JSP or Servlet that the form's action points to, you would use:

String[] vals = request.getParameterValues("val");

Then if you want to pass that in to your class, you could do like:

Calcs c = new Calcs();
c.setVal(vals);

Your class won't work as is, by the way, because you didn't give it a constructor:

  public void Calcs() 
  {
     //Default constructor
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top