0

i have problem in uploading file here is my code this is my form where Plot Location Picture is a file field

<form method="POST" enctype="multipart/form-data" id="plotData" action="${request.contextpath}/FrontEnd/resources/saveplot?${_csrf.parameterName}=${_csrf.token}">
    <fieldset>
        <table class="diffaddsocc">
            <input type="hidden" name="societyBlockId" />
            <tr>
                <td>
                    <div>
                        <label>Property Number:</label>
                        <input type="text" name="propertyNumber" id="adcssno" />
                    </div>
                </td>
                <td>
                    <div>
                        <label>Plot Size:</label>
                        <select name="size" id="sizeid321" class="sizeclass321"> 
                </select>
                    </div>
                    <div>
                        <label>Plot Front Face:</label>
                        <input type="text" name="plotFrontFace" id="adcssno" />
                    </div>
                </td>
                <td>
                    <div>
                        <label>Plot Location Picture:</label>
                        <input type="file" name="fileup" id="fileup" />

                    </div>
                </td>
                <td>
                    <div>
                        <label>Plot Location Picture Date:</label>
                        <input type="date" name="plotLocationPictureDate" />
                        <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
                        <input type="submit" tabindex="-1" style="position:absolute; top:-1000px">
        </table>
    </fieldset>
</form>

this is my ajax jquery function that is called by submitting the form

$(function() {
         addPlot = $( "#plot-form" ).dialog({
              autoOpen: false,
              height: 790,
              width: 1300,
              modal: true,
              buttons: {
                  "Save": addPlotInfo,
                    Cancel: function() {
                        addPlot.dialog( "close" );
                  }
                },
                close: function() {
                    document.getElementById('plotData').reset();
                }
            });
            $( "#add-plot" ).button().on( "click", function() {
                $( '#plot-form input[name="societyBlockId"]' ).val(subSocietyId); 
                addPlot.dialog( "open" );
            });
          });
    function addPlotInfo()
    {


        var formData = new FormData(document.getElementById("plotData"));

        console.log(formData);


                        $.ajax({
                            url: 'saveplot',
                            type: 'post',
                            data: formData,
                            processData: false,
                            contentType: false,
                            success: function (response, status, xml) {
                                if (response == "success") {
                                    addPlot.dialog( "close" );
                                    document.getElementById('plotData').reset();
                                    loadBahriaTable();
                                } else {
                                    alert("There is an error while adding plot. Try again.");
                                }
                            }
                        });

    }

this is my controller method

@RequestMapping(value = "/saveplot", method = RequestMethod.POST)
    public @ResponseBody String Save(HttpServletRequest request,SocietyBlock societyBlock,
            Plot plot,  @RequestParam("fileup") MultipartFile file, BindingResult bindingResult, Model model, 
            @RequestParam(required = false) Boolean reverseBeforeSave) {

        String plottype = request.getParameter("plottypes12");
        String plotstatus = request.getParameter("plotstatus12"); 
        String[] plotfeatures = request.getParameterValues("plotfeas");
        plot.setSocietyBlock(societyBlock);
        propertyService.addPlot(plot, plottype, plotstatus, plotfeatures);
        return "success";
    }

i have tried over 20 30 tutorials online, have seen alot of question in stackoverflow, but it couldn't solve my problem i always get this error

error: Feb 24, 2016 10:54:06 AM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver logException
WARNING: Handler execution resulted in exception: Request method 'POST' not supported

please let me know how to remove this error i have waste my 6 hours but could not able to fix this error..kindly if my code require any change tell me, it'll highly appreciable if anyone solve this error for me??

Ahmad
  • 1,462
  • 5
  • 17
  • 40

0 Answers0