Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding objects to controls on JSP pages
    text
    copied!<p>I have the following class that I'm using in my Java with JSP applicaton.</p> <p>// public class QuestionBO implements Serializable{</p> <pre><code>private int questionId; private int testID; private String question; private TutorBO infoAboutTutor; private SubjectBO infoAboutSubject; private TestBO infoAboutTest; private List&lt;AnswerBO&gt; answers; public QuestionBO() { } public QuestionBO(String question) { this.question = question; } </code></pre> <p>getter &amp; setter....</p> <p>The JSP page has a form where each Question (its String representation) has a checkbox next to it. A user marks some of the questions and submits the form to the server for processing by a servlet.</p> <p>What is the conventional way of binding the Question objects with the checkboxes so that I could find out what Questions have been selected?</p> <p>Currently I'm using the following approach for constructing the form:</p> <p>// </p> <pre><code> &lt;c:if test="${not empty questionsForSubject}"&gt; &lt;form action="/TutorWebApp/controller" method="POST" name="addQuestionForm"&gt; &lt;input type="hidden" name="command" value="add_question_list" /&gt; &lt;input type="hidden" name="testName" value="${testName}"/&gt; &lt;table border ="1"&gt; &lt;tbody&gt; &lt;c:forEach items="${questionsForSubject}" var="question"&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" name ="choosen_question" value="${question.getQuestion()}"&gt; ${question.getQuestion()} &lt;br /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;input type="submit" value="Add questions "/&gt; &lt;/form&gt; </code></pre> <p>And I shouldn't use frameworks.</p> <p>Thanks</p> <p>And I have last question </p> <pre><code> &lt;c:if test="${not empty questionsForSubject}"&gt; &lt;form action="/TutorWebApp/controller" method="POST" name="addQuestionForm"&gt; &lt;input type="hidden" name="command" value="add_question_list" /&gt; &lt;input type="hidden" name="testName" value="${testName}"/&gt; &lt;input type="hidden" name="questionsForSubject" value="${questionsForSubject}"/&gt; &lt;table border ="1"&gt; &lt;tbody&gt; &lt;c:forEach items="${questionsForSubject.keySet()}" var="questionID"&gt; &lt;tr&gt; &lt;td&gt; &lt;input type="checkbox" name ="choosen_question" value="${questionID}"&gt; ${questionsForSubject.get(questionID).getQuestion()} &lt;br /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;input type="submit" value="Добавить вопросы"/&gt; &lt;/form&gt; </code></pre> <p>How I can get map from this page on servlet?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload