Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Value of dynamically create dropdownlist in JSP
    primarykey
    data
    text
    <p>I am new to JSP and servlet for 1 month, and there are many things that I am still unsure off.. Inside a JSP, I have a dropdownlist(the values inside are grab from database) and it would be dynamically created on the number that the user keyed in. Example, the user key in 3, this digit would store in session, and 3 dropdownlist would be generated. </p> <p>I am able to do this, however I am unable to grab the value of all the 3 dropdownlist in a servlet. and instead of getting 3 diff values, the output repeat the value of the first dropdownlist. Example "john,john,john" instead of "john, ken, andy". </p> <p>JSP code: </p> <pre><code> &lt;form action="Adding" method="post"&gt; &lt;% session = request.getSession(); ProjectGroup projGrp1 = (ProjectGroup)session.getAttribute("PROJECTNAME"); //getMaxMember is the int that user keyed in int staff =projGrp1.getMaxMember(); for(int i = 0; i &lt; staff; i++) { %&gt; &lt;select name="list1" &gt; &lt;%@page import="sit.bean.*,sit.data.*"%&gt; &lt;% GroupTaskManager mgr3 = new GroupTaskManager(); GroupTask[] at3 = mgr3.getCheckBox(); for(int g = 0; g &lt; at3.length; g++) { %&gt; &lt;option&gt;&lt;%=at3[g].getStaffName()%&gt;&lt;/option&gt; &lt;% } %&gt; &lt;/select&gt; &lt;% } %&gt; &lt;input type="submit" name="submit"&gt; &lt;/form&gt; </code></pre> <p>In servlet: </p> <pre><code>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); ProjectGroup projGrp = (ProjectGroup)session.getAttribute("PROJECTNAME"); int member = projGrp.getMaxMember(); String total = null; for(int i=0; i&lt; member; i++) { String names = request.getParameter("list1"); total += names + " , "; } PrintWriter pw = response.getWriter(); pw.write("&lt;HTML&gt;&lt;BODY&gt;"); pw.write(total); pw.write("&lt;/HTML&gt;&lt;/BODY&gt;"); pw.close(); } </code></pre> <p>Can i set the downdownlist name like "list&lt;%i%>", to set different id to each downdownlist? therefore i can retrieve each of them seperately??? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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