1
當我嘗試訪問以下方法時,我收到(客戶端發送的請求在語法上不正確)錯誤。Spring MVC文件上傳 - 客戶端發送的請求在語法上不正確
@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一部分文件上傳:
<form:input path="prosConsentForm" id="consentForm" type="file" style="display:initial" name="consentForm"/>
DAO實現方法:
@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();
}
幫助我在這裏:
這是customProspectList模型類。
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
這是形式:
<form:form commandName="prospect" action="${pageContext.request.contextPath}/prospect/prospectupdated" method="post" enctype="multipart/form-data" accept-charset="utf-8">
........
</form:form>
請填寫完整的堆棧跟蹤。 –
對不起,我沒有得到控制檯中的任何堆棧跟蹤,我得到HTTP狀態400 - 只有...這個描述「客戶端發送的請求語法不正確。」 – karthi
請發佈完整的http表單以及'CustomProspectList'類,問題可能與他們有關係。順便說一句:你的表單必須具有multipart參數集,並且你需要在Spring中註冊一個註冊MultipartResolver/Filter。 https://spring.io/guides/gs/uploading-files/ – Ralph