0

I'm making a web application where you need to register and login. Very basic, I know but I'm learning it.

Now I want to show a list of checkboxes in a JSP page. I have something like this:

 <% KokenHelper kh= new KokenHelper(); %>
      <c:forEach var="wat" items="${kh.getAllKoken()}" >
           <div class="checkbox">
                <label>
                     <input type="checkbox" name="wat" value="${wat}"> ${wat}
                </label>
           </div>
      </c:forEach>

I made a KokenHelper class that gets a List object, that is what I need to show.

Any tips are welcome.

Thank you.

ivancoene
  • 150
  • 4
  • 16

1 Answers1

1

First, dont use Java code in a jsp page

<% KokenHelper kh= new KokenHelper(); %>

JSTL IT'S DEPRECATED AND HIGHLY DISCOURAGED:


Second: KokenHelper class must have the list of Koken as private attribute and it's publics getters and setters:

class KokenHelper {
    private List<Koken> kokenList;

    // getter and setter!!!
} 

Third, depending how you pass the information from java to view you can get the kokenList via:

${applicationScope.kokenHelper.kokenList}

using a form:

<form:form role="form" method="post" commandName="kokenHelper" action="../formAction" id="formId">
    <c:forEach var="wat" items="${kokenHelper.kokenList}" >
</form:form>

But to be more concrete I should have more info...

Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • Thank you for your answer. I know that I might not use java in a jsp page but I don't know how I'm supposed to do it without. The second step like mine. The problem is in the Third step: I don't know how to pass the data to the jsp... – ivancoene Feb 17 '16 at 17:29
  • Wat more info do you need? I'll post it – ivancoene Feb 17 '16 at 18:03
  • there is plenty of ways, first one `${applicationScope.kokenHelper.kokenList}` should work in all cases... also [check this](https://www.google.es/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=jsp%20tutorial%20java) – Jordi Castilla Feb 18 '16 at 15:08