简体   繁体   中英

Retrieve jsp value in servlet

I have a problem with the recovery of the values of my JSP in my Servlet.

My JSP contains one input and two select.

I would like to retrieve the values of these elements and pass them in my servlet, but the result in my servlet is still null.

String histoDate = request.getParameter("cDate");
String intervalleHeure = request.getParameter("cHeure");
String statut = request.getParameter("cStatut");

And in my JSP I create these elements in jQuery

"<label>Date : <input class='form-control' type='text' value='05/07/2018' placeholder='Cliquer pour choisir' id='histoDate' name='histoDate'>&nbsp;&nbsp;&nbsp;</label>"
"<label>Heure : <select id='demo-foo-filter-nbTrame' class='form-control selectpicker' id='intervalleHeure' name='intervalleHeure'>"
"<select id='demo-foo-filter-status' class='form-control selectpicker' id='statut' name='statut'>"

And I try to access my servlet with a function and I pass in argument the necessary values

function valeurHistorique(cDate, cHeure, cStatut){
        $.ajax({
            dataType: "json",
            url: "/Production/Maintenance/JSONHistorique",
            data: {
                histoDate: cDate,
                heure : cHeure,
                statut : cStatut
            },

My three values are still null in my servlet, I am really stuck. Thank you for your help

When you send ajax request parameters will be named as left part of object data.

histoDate, heure, statut .

Try it:

String histoDate = request.getParameter("histoDate");
String intervalleHeure = request.getParameter("heure");
String statut = request.getParameter("statut");

Also if you could see all parameters in httpServletRequest.getParameterMap();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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