简体   繁体   中英

Spring MVC File Upload - The request sent by the client was syntactically incorrect

I'm getting (The request sent by the client was syntactically incorrect) error, when I try to access the following method.

@RequestMapping ( value = "/prospect/prospectupdated", method = RequestMethod.POST )
    public String prospectUpdated ( @ModelAttribute("prospect") CustomProspectList customProspectList, @RequestParam("consentForm") MultipartFile file ) throws IOException {

        int id = customProspectList.getProsId();

        String consentFormStatus = prospectService.consentFormStatus(id);

        byte[] consentFormFile = file.getBytes();
        String consentFormName = file.getOriginalFilename();
        long consentFormSize = file.getSize();
        String consentFormType = file.getContentType();

        if ( consentFormStatus.equals("Y") && consentFormSize != 0 ){
            prospectService.updateConsentForm(id, consentFormName, consentFormSize, consentFormFile, consentFormType);
        }

        return "success";
    }

JSP part for file upload :

<form:input path="prosConsentForm" id="consentForm" type="file" style="display:initial" name="consentForm"/>

DAO implementation method :

@Override
    public void updateConsentForm(int id, String consentFormName, long consentFormSize, byte[] consentFormFile, String consentFormType) {
        Session session = sessionFactory.getCurrentSession();
        String sql = "UPDATE ccm_prospect SET PROS_Consent_Form_Name = :ConsentFormName, PROS_Consent_Form_Size = :ConsentFormSize, PROS_Consent_Form_File = :ConsentFormFile, PROS_Consent_Form_Type = :ConsentFormType WHERE PROS_Id = :ProspectId";
        SQLQuery query = session.createSQLQuery(sql);
        query.setParameter("ConsentFormName", consentFormName);
        query.setParameter("ConsentFormSize", consentFormSize);
        query.setParameter("ConsentFormFile", consentFormFile);
        query.setParameter("ConsentFormType", consentFormType);
        query.setParameter("ProspectId", id);
        query.executeUpdate();
    }

Help me here :

This is the customProspectList model class.

public class CustomProspectList {

    private int prosId;

    private String prosDOB;

    private String prosTrackingStatus;

    private String prosFirstName;

    private String prosLastName;

    private String prosMiddleName;

    private String prosGender;

    private String prosEmail;

    private String prosMobilePhone;

    private String prosHomePhone;

    private String prosWorkPhone;

    private String prosCommuMethod;

    private String prosAddrLine1;

    private String prosAddrLine2;

    private String prosCity;

    private String prosState;

    private String prosZipCode;

    private byte[] prosConsentForm;

    private byte[] prosHippaForm;

    private String prosConsentFormName;

    private String prosHippaFormName;

    private String prosConsentFormDate;

    private String prosHippaFormDate;

    private BigInteger prosConsentFormSize;

    private BigInteger prosHippaFormSize;

    private String provNPI;

    private String faciName;

    private String faciAddrState;

    private String persFirstName;

    private String persLastName;

    private String persMiddleName;

    private String prosConsentFormType;

    //getters & setters

This is the form :

<form:form commandName="prospect" action="${pageContext.request.contextPath}/prospect/prospectupdated" method="post" enctype="multipart/form-data" accept-charset="utf-8">
  ........
  </form:form>

Try to bind your file to :

private MultipartFile prosConsentForm;

instead of a byte array.

If this doesn't work just turn your logger to debug for org.springframework

For every 40X error spring doesn't write error log but in debug it will cleary tell you the reason.

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