Dave Daniels wrote:
>
> How do I place form elements in an array? For example, in PHP I might do
> something like:
>
> <input type="checkbox" name="test[]" value="v1">
> <input type="checkbox" name="test[]" value="v2">
> <input type="checkbox" name="test[]" value="v3">
>
> The target of the form can then work with the array 'test'. Is there a
> similar feature with JSP?

If you have a group of form elements with the same name, as in your
example, all values are made available as a String[] to the servlet
or JSP page that handles the request. In servlet code, you get access
to the array with getParameterValues("theFieldName"). In JSP, you can
use the same code in a scriptlet, but to avoid code in the page it's
typically better to use a bean with a String[] property:

  <jsp:useBean id="formData" class="myFormHandler">
    <jsp:setProperty name="formData" property="*" />
  </jsp:useBean>

The class has a setter method like this, assuming the field name
(parameter name) is, literary, "fieldName":

  public void setFieldName(String[] values) {
    ...
  }

You may also want to look at developing a custom action to process
the data.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com
Author of JavaServer Pages (O'Reilly), http://TheJSPBook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to