0

I have Spring MVC application with this controller method.

@RequestMapping(value = "/saveMe", method = RequestMethod.POST)
   public @ResponseBody String saveMe(@RequestParam(value = "clientId") String strClientId,@RequestParam(value = "clientName") String strClientName,@RequestParam(value = "custBaseNo") String strCustBaseNo, @RequestParam(value = "category") String strCategory,@RequestParam(value = "clientCpt") String strClientCpt, @RequestParam(value = "pbk") String strPbk,@RequestParam(value = "prk") String strPrk,@RequestParam(value = "fileAct") int intFileAct, @RequestParam(value = "b2b") int intB2b,@RequestParam(value = "collection") int intCollection, @RequestParam(value = "primAccNo") String strPrimAccNo,@RequestParam(value = "accFromAcct") String strAccFromAcct,@RequestParam(value = "accToAcct") String strAccToAcct,@RequestParam(value = "intCount") int intCount,@RequestParam(value = "productId") String strProductId,HttpServletRequest request){
        String strStatus ="";
        System.out.println("strClientId is :::"+strClientId);
        strStatus = sabService.saveDetails(strClientId,strClientName,strCustBaseNo,strCategory,strClientCpt,strPbk,strPrk,intFileAct,intB2b,intCollection,strPrimAccNo,strAccFromAcct,strAccToAcct,intCount,strProductId);

        String[] strChkService = new String[intCount]; 
        String[] strAccNO = new String[intCount]; 
        int[] intTrnsLimit = new int[intCount]; 
        String[] strProtcl = new String[intCount]; 
        for(int j=1;j<=intCount;j++){
            strChkService[j] = request.getParameter("chkService"+j)==null?"":request.getParameter("chkService"+j);
            strAccNO[j]      = request.getParameter("accountNo"+j)==null?"":request.getParameter("accountNo"+j);
            intTrnsLimit[j]  = Integer.parseInt(request.getParameter("transactionLimit"+j)==null?"0":request.getParameter("transactionLimit"+j));
            strProtcl[j]     = request.getParameter("protocol"+j)==null?"":request.getParameter("protocol"+j);

            strStatus = sabService.saveServices(strClientId,strProductId,strChkService[j],strAccNO[j],intTrnsLimit[j], strProtcl[j] );
        }
        return "success";
    }

While submitting the form I'm getting this error.

HTTP Status 400 - Required String parameter 'clientId' is not present

Can anyone please help me...Thanks in advance...

jquery-

 $("#client-maint-form").attr("action","sabb/saveMe");
              $("#client-maint-form").submit();

form-

 <form id="client-maint-form" class="form-horizontal" enctype="multipart/form-data" method="POST">

i have also tried with GET ...but getting this error
HTTP Status 405 - Request method 'GET' not supported

Here is the form

<form id="client-maint-form" class="form-horizontal" enctype="multipart/form-data" method="POST">
            <div class="box-body">
                <div class="form-group">
                    <label for="client-id" class="col-sm-3 control-label">Client Id<a style="color: red">*</a></label>
                    <div class="col-xs-4">
                        <input class="form-control" name="clientId" id="client-id" required="true" placeholder="Client Id" type="text">
                    </div>
                </div>
                <div class="form-group" id="password-div-add-update">
                    <label for="client-name" class="col-sm-3 control-label">Client Name<a style="color: red">*</a></label>
                    <div class="col-xs-4">
                        <input class="form-control" name="clientName" id="client-name" required="true" placeholder="Client Name" type="text">
                    </div>
                </div>
</form>
Tobias Liefke
  • 8,637
  • 2
  • 41
  • 58
Bichu
  • 29
  • 2
  • 9
  • What is the query string you are calling the controller with? Can you confirm that clientId is being passed? – ashosborne1 Nov 20 '15 at 10:04
  • How do you call the controller? – Jens Nov 20 '15 at 10:09
  • @ashosborne1... i'm submitting the form with POST method..no query string is used.. – Bichu Nov 20 '15 at 10:10
  • @jens by just submitting the form using jquery – Bichu Nov 20 '15 at 10:11
  • @Bichu cany you show the jquery code please? – Jens Nov 20 '15 at 10:12
  • @jens jquery- $("#client-maint-form").attr("action","sabb/saveMe"); $("#client-maint-form").submit(); – Bichu Nov 20 '15 at 10:16
  • @Jens form-
    i have also tried with GET ...but getting this error HTTP Status 405 - Request method 'GET' not supported
    – Bichu Nov 20 '15 at 10:18
  • @Please add it to your question using the edit function, not as a comment – Jens Nov 20 '15 at 10:19
  • GET do not work, because your controller only accept POST requests – Jens Nov 20 '15 at 10:20
  • Are you passing `clientId` somehow from the client? One example would be to have `someClientId` inside the form. Same goes for all other parameters you expect in the controller method – Predrag Maric Nov 20 '15 at 10:21
  • @ Predrag Maric All parameters that are getting inside controller are present inside the form as input fields – Bichu Nov 20 '15 at 10:26
  • Please post the whole form – Predrag Maric Nov 20 '15 at 10:26
  • @Predrag Maric please check the form...i have just shown only two input fields as the form is huge... – Bichu Nov 20 '15 at 10:33
  • Does it work if you remove `enctype="multipart/form-data"`? – Predrag Maric Nov 20 '15 at 10:34
  • @ Predrag Maric when i remove enctype="multipart/form-data" i'm getting error code 400 in browser – Bichu Nov 20 '15 at 10:39
  • Same one as before, or a different one? See if [this](http://stackoverflow.com/a/17964870/4074715) helps – Predrag Maric Nov 20 '15 at 10:53
  • @ Predrag Maric different error code...only HTTP 400 – Bichu Nov 20 '15 at 11:02
  • 1
    While not an answer, one primary reason for using a framework is to avoid the tedious binding of submitted parameters to domain objects. You're code would be a lot cleaner if you created a Model object and bound your form to that rather than working with individual params. See, for example: http://www.baeldung.com/spring-mvc-form-tutorial – Alan Hay Nov 20 '15 at 13:32
  • You can narrow down the problem by setting required=false on the @RequestParam annotation for clientId. If the method executes (with an error obviously) then you know it is a problem only with that param. If it complains about the next one in the list then you know it is something else. – Alan Hay Nov 20 '15 at 13:35

0 Answers0