简体   繁体   English

JSP / Servlet中的隐藏表单

[英]Hidden form in JSP/Servlet

I want to get parameters from my jsp to my servelet. 我想从我的jsp获取参数到我的servelet。 so i used input form and it works for the name and the last name but it doesn't work for my ID. 所以我使用输入形式,它可以用于名称和姓氏,但不能用于我的ID。 Here is the code of my JSP: 这是我的JSP的代码:

<tr>
                <td><form method="post" action="ServBddInsa">
                    <input type="hidden" name="id" id="id" value="testId"/>
                    <c:out value="${ utilisateur.id }" />
                    </form>
                </td>                                                           
                <td><c:out value="${ utilisateur.prenom }" /></td>
                <td><c:out value="${ utilisateur.nom }" /></td>
                <td><form method="post" action="ServBddInsa">                   
                        <p>                         
                            <label for="prenom"> Prenom :</label> <input type="text"
                                id="prenom" name="prenom" />                                                
                            <label for="nom"> Nom :</label> <input type="text" id="nom"
                                name="nom" />
                        </p>
                        <input type="submit" name="editer" value="editer" />

                    </form></td>
            </tr>
        </c:forEach>

and this of my servlet: 这是我的servlet:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BddInsa listU = new BddInsa();
        request.setAttribute("utilisateur", listU.recupererList());
        this.getServletContext().getRequestDispatcher("/WEB-INF/bddinsa.jsp").forward(request, response);


    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {      
        Utilisateur utilisateurs = new Utilisateur();
        utilisateurs.setNom(request.getParameter("nom"));
        utilisateurs.setPrenom(request.getParameter("prenom"));     
        utilisateurs.setId(request.getParameter("id"));             
        System.out.println(utilisateurs.getPrenom());
        System.out.println(utilisateurs.getNom());
        System.out.println(utilisateurs.getId());
        BddInsa listU = new BddInsa();
        listU.Editer(utilisateurs);     
        request.setAttribute("utilisateurs", listU.recupererList());
        this.getServletContext().getRequestDispatcher("/WEB-INF/bddinsa.jsp").forward(request, response);

    }


}

I get NULL when I try to see the value of id 尝试查看id的值时得到NULL

Thank you for your help ! 谢谢您的帮助 !

Please can you try to use only one open and one close form tag? 请您尝试只使用一个打开和一个关闭表单标签吗? I think you problem is because you have two <form method="post" action="ServBddInsa"> . 我认为您的问题是因为您有两个<form method="post" action="ServBddInsa"> So the submit button is on the second form. 因此,提交按钮位于第二个表单上。 In this case the hidden field of the first form is not considered and it is not sent. 在这种情况下,将不考虑第一种形式的隐藏字段,并且不会发送它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM