使用按钮将 jsp 参数传递给另一个

pass jsp parameter to another using button

所以我试图将选定的值从 jsp 中的组合框传递到另一个 jsp 这就是我进入的

<form name="ff" method="post">  
         <select name='mat' id='soflow'>
        <% ArrayList<Matiere> listeM = MatiereListe.GetMatiere(); %>
       <option></option>
        <% for (Matiere d : listeM)
        { %>
            <option value= <%=d.getCode_mat() %> >
                     <%=d.getLib_mat() %>
            </option>
        <% } %>
         </select>
         <input type=submit value=valider  />
        <br>
        </form>
         <button onclick="window.location.href='/acceuil.jsp?mat=' JSGetSelectedItemMat() " >Statistique</button>
<script>
        function JSGetSelectedItemMat()
        {
            var e = document.getElementById("soflow");
            var strSel = e.options[e.selectedIndex].value;
            document.getElementById("btt").value = strSel;    
        } 
        </script>

尝试使用此代码从 select 标签获取 selected 值。由于不需要使用 js,因此您在 html 表单中使用了 post 方法。还使用 getParameter 方法获取 acceuil.jsp 中的值。即 request.getParameter("mat");

<form action="acceuil.jsp" name="ff" method="post">  
         <select name='mat' id='soflow'>
        <% ArrayList<Matiere> listeM = MatiereListe.GetMatiere(); %>
       <option></option>
        <% for (Matiere d : listeM)
        { %>
            <option value= <%=d.getCode_mat() %> >
                     <%=d.getLib_mat() %>
            </option>
        <% } %>
         </select>
         <input type=submit value=valider  />
        <br>
        </form>