2016-09-02 158 views
0

有兩種形式,每種在我的jsp頁面都有一個提交按鈕...我想將表單1發送給我的控制器它由兩個圖像和幾個表單域組成。Spring MVC: - 表單提交(HTTP狀態400 - 客戶端發送的請求在語法上是不正確的。)

Controller.java

@RequestMapping(value="/schoolDetails",method=RequestMethod.GET) 
    public ModelAndView getschoolDetails(){ 

    ModelAndView model = new ModelAndView(); 
    School schools=new School(); 
    Map referenceData = new HashMap(); 
    referenceData.put("schoolObject", schools); 
    ModelAndView mav = new ModelAndView("schoolDetails", referenceData);  
    return mav; 
} 



@RequestMapping(value="/addSchoolDetails",method=RequestMethod.POST) 
public String addSchoolDetails(@ModelAttribute("schoolObject") School school, 
     @RequestParam("image") MultipartFile image,@RequestParam("logo") MultipartFile logo){ 

    if(result.hasErrors()){ 
     return "schoolDetails"; } 

    Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 
    CustomUser user=null; 
    if (principal instanceof CustomUser) { 
    user = ((CustomUser)principal); 
    } 

    return "schoolDetails"; 
} 

schoolDetails.jsp

<form:form method="POST" role="form" action="/GenericApp/addSchoolDetails" enctype="multipart/form-data" modelAttribute="schoolObject"> 

    <div class="col s3" id="sName">School Name :</div> 
    <input id="form_text" name="schoolname" type="text" placeholder="School Name"/> 

    <div class="col s3" id="sName">Email ID :</div> 
    <input id="form_text" name="email" type="email" placeholder="Email ID"/> 

    <div class="col s3" id="sName">State :</div> 
    <select name="state" id="state_id" > 
     <option>State</option> 
     <option>Karnataka</option>            
    </select> 
    <div class="col s12 m4 l4" id="sName">Upload School Logo :</div> 
     <input type="file" name="logo" id="fileUpload" accept="image/x-png, image/gif, image/jpeg"/> 
                   <span class="button teal ">Choose a Image</span> 
    <button class="waves-effect waves-light btn" type="submit" name="action">Submit</button> 
    </form:form>    
+0

請把你所有的jsp代碼。 –

+0

可能是他們提到的錯誤行號。所以你可以請他們分享哪一行顯示這個錯誤? –

+0

@JekinKalariya我在帖子中添加了jsp頁面的部分內容。只要我點擊提交它顯示我「請求發送的客戶端語法不正確」 –

回答

0

由於JSP中不含有與名稱,圖像附加標籤也名圖像糾正你的JSP文件,如下

任何標籤
<form:form method="POST" role="form" action="/GenericApp/addSchoolDetails" enctype="multipart/form-data" modelAttribute="schoolObject"> 

    <div class="col s3" id="sName">School Name :</div> 
    <input id="form_text" name="schoolname" type="text" placeholder="School Name"/> 

    <div class="col s3" id="sName">Email ID :</div> 
    <input id="form_text" name="email" type="email" placeholder="Email ID"/> 

    <div class="col s3" id="sName">State :</div> 
    <select name="state" id="state_id" > 
     <option>State</option> 
     <option>Karnataka</option>            
    </select> 
    <div class="col s12 m4 l4" id="sName">Upload School Logo :</div> 
     <input type="file" name="logo" id="fileUpload" accept="image/x-png, image/gif, image/jpeg"/> 
                   <span class="button teal ">Choose a Image</span> 
<input type="file" name="image" id="image" accept="image/x-png, image/gif, image/jpeg"/> 
    <button class="waves-effect waves-light btn" type="submit" name="action">Submit</button> 
    </form:form>  
相關問題